spring service事物,service调用service,不回滚

跑跑鱼 2010-11-12 10:18:21
如题,spring事物在service层,我在一个service层调用另一个service的方法,这样事物回滚就不管用了。请问这个问题怎么解决呢
...全文
2202 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
china_agh20 2011-02-22
  • 打赏
  • 举报
回复
butaimingabi
  • 打赏
  • 举报
回复
如果要抛出非 RuntimeException 的受检查异常的话,需要在 Spring 指定 rollback for
跑跑鱼 2010-11-16
  • 打赏
  • 举报
回复

我的一个service层方法可以被多次调用,所有出现这样的需求。的确,这种方法存在问题,有待改进,谢谢楼上的提醒
helloworld52 2010-11-16
  • 打赏
  • 举报
回复
http://www.examda.com/Java/zhuangye/20100309/090149245.html
sotom 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 jsjxieyang 的回复:]

问题已经解决了。还是分享一下吧
spring 这样配置:propagation="REQUIRED",在事物层想要回滚必须有异常抛出,而且自己不能捕获,抛出的异常必须是runtimeexception.
我spring 不回滚就是因为我强制抛了一个非runtimeexception的异常。

仍然感谢各位的回答。
[/Quote]

业务层调用业务层,不会出现事务嵌套么???,你这样开发有问题的。
跑跑鱼 2010-11-16
  • 打赏
  • 举报
回复
问题已经解决了。还是分享一下吧
spring 这样配置:propagation="REQUIRED",在事物层想要回滚必须有异常抛出,而且自己不能捕获,抛出的异常必须是runtimeexception.
我spring 不回滚就是因为我强制抛了一个非runtimeexception的异常。

仍然感谢各位的回答。
gaoxulaiguo 2010-11-16
  • 打赏
  • 举报
回复
打酱油?楼主懂事务的传播性吗?
gaoxulaiguo 2010-11-15
  • 打赏
  • 举报
回复
你研究下SPRING的事务传播性
米土木木 2010-11-15
  • 打赏
  • 举报
回复
Spring有个配置文件提交事物


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>

<bean id="baseDao" abstract="true" class="com.comm.HibernateBaseDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="goodsDao" class="com.daoimpl.GoodsDaoImpl" parent="baseDao"></bean>
<bean id="goodstypeDao" class="com.daoimpl.GoodstypeDaoImpl" parent="baseDao"></bean>
<bean id="usersDao" class="com.daoimpl.Users2DaoImpl" parent="baseDao"></bean>

<bean id="goodsService" class="com.serviceimpl.GoodsServiceImpl">
<property name="igoodsDao" ref="goodsDao"></property>
<property name="igoodstypeDao" ref="goodstypeDao"></property>
<property name="iusers2Dao" ref="usersDao"></property>
</bean>

<bean id="goodsAction" class="com.struts2.action.GoodsAction">
<property name="igoodsService" ref="goodsService"></property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" parent="baseDao"></bean>

<tx:advice id="mytx" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:advisor advice-ref="mytx" pointcut="execution(* com.iservice.*.*(..))"/>
</aop:config>

</beans>
跑跑鱼 2010-11-15
  • 打赏
  • 举报
回复
我发现大家大部分都是打酱油的吧
che253604783 2010-11-13
  • 打赏
  • 举报
回复
要么是你用的不对,要么就把事物再往service上提一层
跑跑鱼 2010-11-13
  • 打赏
  • 举报
回复
自己找了两篇文章
http://ajava.org/course/open/13028.html
http://www.examda.com/Java/zhuangye/20100309/090149245.html
安心逍遥 2010-11-13
  • 打赏
  • 举报
回复
这方面还不是很懂,帮顶。祝楼主好运
tubage408 2010-11-12
  • 打赏
  • 举报
回复
事务配置,具体代码
sound9world 2010-11-12
  • 打赏
  • 举报
回复
会这样嘛 ...这样用过 不过忘记测试过没了。。mark下

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧