[quote]在applicationContext.xml中配置如下:[/quote]
[quote]注:当方法内抛出运行时异常时,事务便会回滚。[/quote]
<!--hibernate 事务-->
<bean id="HibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事务拦截,以下面固定格式开头的方法都在事务包含之列 -->
<tx:advice id="HiberbateTxAdvice"
transaction-manager="HibernateTransactionManager">
<tx:attributes>
<tx:method name="insert*" rollback-for="Throwable" />
<tx:method name="update*" rollback-for="Throwable" />
<tx:method name="delete*" rollback-for="Throwable" />
<tx:method name="add*" rollback-for="Throwable" />
<tx:method name="save*" rollback-for="Throwable" />
<tx:method name="remove*" rollback-for="Throwable" />
<tx:method name="modify*" rollback-for="Throwable" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 事务覆盖范围:com.kedacom.kdkk.service包下面的所有类 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="serviceOperation"
expression="execution(* com.kedacom.kdkk.service..*.*(..))" />
<aop:advisor pointcut-ref="serviceOperation"
advice-ref="HiberbateTxAdvice" />
</aop:config>
[quote]注:当方法内抛出运行时异常时,事务便会回滚。[/quote]