一个简单的hibernate与spring集成 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-15
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
一个简单的hibernate与spring集成(4)时间:2011-09-09 blogjava qin测试类:SpringDaoTest.java package org.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import springDao.Sstest; import springDao.SstestDAO; public class SpringDaoTest { public static void main(String a[]){ ApplicationContext cont = new ClassPathXmlApplicationContext ("applicationContext.xml"); //SstestDAO s = (SstestDAO) cont.getBean("SstestDAO"); //代理类 SstestDAO s = (SstestDAO) cont.getBean("SstestDAOProxy"); Sstest st = new Sstest(); st.setUsername("spring"); st.setPassword("spring"); s.save(st); } } Sstest.hbm.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="springDao.Sstest" table="sstest" schema="dbo" catalog="manager"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="increment" /> </id> <property name="username" type="java.lang.String"> <column name="username" length="10" /> </property> <property name="password" type="java.lang.String"> <column name="password" length="20" /> </property> </class> </hibernate-mapping> 一个简单的hibernate与spring集成(5)时间:2011-09-09 blogjava qinSstestDAO.java package springDao; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.springframework.context.ApplicationContext; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class SstestDAO extends HibernateDaoSupport { private static final Log log = LogFactory.getLog(SstestDAO.class); // property constants public static final String USERNAME = "username"; public static final String PASSWORD = "password"; protected void initDao() { // do nothing } public void save(Sstest transientInstance) { log.debug("saving Sstest instance"); System.out.println("Ok"); try { getHibernateTemplate().save(transientInstance); log.debug("save successful"); System. |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于一个简单的hibernate与spring集成 - 编程入门网的所有评论