Spring事宜控制
Spring事务控制(单数据源)Hibernate与JDBC事务统一?http://www.blogjava.net/leekiang/archive/2009/12/11
Spring事务控制
(单数据源)Hibernate与JDBC事务统一
?
http://www.blogjava.net/leekiang/archive/2009/12/11/305492.html?
写道
</property>
</bean>
<!-- sqlserver 数据库sessionFactory -->
<bean id="sessionFactoryForSqlServer" />
</property>
</bean>
(3)为dao注入对应的session工厂
<bean id="sqlServerbaseDao" />
</property>
</bean>
4、手动提交:Dao实现中采用手动提交和回滚事务的办法,避免数据库因事务不能及时提交而引起死锁现象
this.getSession().clear();
Transaction tx = null;
try{
tx = this.getSessionFactory().getCurrentSession().beginTransaction();
//这里写你的操作数据库的代码:例如:
this.getHibernateTemplate().update(objBean);
tx.commit();
}catch(RuntimeException e){
if(tx != null)tx.rollback();
throw e;
}finally{
//this.getSession().close();
}
?