`
arantam
  • 浏览: 40967 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

Spring + Hibernate spring管理事务

阅读更多

spring配置事务处理,选择annotation驱动的方式.

1.在配置文件中加入schema.

 

xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"

 

2.声明事务管理器

 

	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager"
		proxy-target-class="true" />

 

3.在Service中声明事务:@Transactional.

 

据说这是最佳方法.俺配上去用了,没什么地方报异常,但也不知道是不是就成功了?呵呵..得测试一下.

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics