我用spring3配了一段事务,配置文件代码如下:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/> <aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* biz.impl.*.*(..))" />
<aop:advisor pointcut-ref="serviceOperation"
advice-ref="txAdvice" />
</aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>biz.impl.RegisterBizImpl类中代码
public void add(Test test) throws Exception {
registerDao.insert(test);
throw new Exception("xx");
}
但抛出异常后数据还是进入了数据库,请高手帮忙,如需要其他代码请提出,我还可以继续贴
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/> <aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* biz.impl.*.*(..))" />
<aop:advisor pointcut-ref="serviceOperation"
advice-ref="txAdvice" />
</aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="edit*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>biz.impl.RegisterBizImpl类中代码
public void add(Test test) throws Exception {
registerDao.insert(test);
throw new Exception("xx");
}
但抛出异常后数据还是进入了数据库,请高手帮忙,如需要其他代码请提出,我还可以继续贴
你抛个RuntimeException试试。
抛一个运行时异常看看。
new RunningTimeException()