问题描述
事务配置<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><beanid="ghm_DataSource"class="org.springframework.jndi.JndiObjectFactoryBean"><propertyname="jndiName"><value>java:comp/env/jdbc/ghm_jdbc</value></property></bean><beanid="ghk_DataSource"class="org.springframework.jndi.JndiObjectFactoryBean"><propertyname="jndiName"><value>java:comp/env/jdbc/ghk_jdbc</value></property></bean><beanid="ghc_DataSource"class="org.springframework.jndi.JndiObjectFactoryBean"><propertyname="jndiName"><value>java:comp/env/jdbc/ghc_jdbc</value></property></bean><beanid="ghm_sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><propertyname="configLocation"><value>classpath:ghy-SqlMap-Config.xml</value></property><propertyname="dataSource"ref="ghm_DataSource"></property></bean><beanid="ghk_sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><propertyname="configLocation"><value>classpath:ghy-SqlMap-Config.xml</value></property><propertyname="dataSource"ref="ghk_DataSource"></property></bean><beanid="ghc_sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><propertyname="configLocation"><value>classpath:ghy-SqlMap-Config.xml</value></property><propertyname="dataSource"ref="ghc_DataSource"></property></bean><beanid="jotm"class="org.springframework.transaction.jta.JotmFactoryBean"/><beanid="transactionManager"class="org.springframework.transaction.jta.JtaTransactionManager"><propertyname="userTransaction"ref="jotm"/></bean><tx:adviceid="txAdvice"transaction-manager="transactionManager"><tx:attributes><tx:methodname="delete*"rollback-for="Exception"/><tx:methodname="save*"rollback-for="Exception"/><tx:methodname="update*"rollback-for="Exception"/><tx:methodname="add*"rollback-for="Exception"/><tx:methodname="select*"read-only="true"/><tx:methodname="get*"read-only="true"/><tx:methodname="find*"read-only="true"/><tx:methodname="query*"read-only="true"/></tx:attributes></tx:advice><beanid="transactionTemplate"class="org.springframework.transaction.support.TransactionTemplate"><propertyname="transactionManager"><refbean="transactionManager"/></property></bean><aop:config><!--切入点--><aop:pointcutid="serviceOperation"expression="execution(*com.speed.speedadmin.ghy.service..*.*(..))"/><aop:advisorpointcut-ref="serviceOperation"advice-ref="txAdvice"/><!--适配器--></aop:config></beans>
service层代码:publicvoidaddChannelInfo(GhManChannelManagerVovo){//TODOAuto-generatedmethodstubStringchannelId=ghManChannelManagerDao.addChannelInfo(vo);//成功插入vo.setChannelId(channelId);ghManChannelManagerDao.addChannelDetail(vo);//由于vo中的某个属性不合法,将产生异常,但是第一个表中的数据已插入,不能回滚是配置的问题吗}
解决方案
解决方案二:
ghManChannelManagerDao.addChannelInfo(vo)ghManChannelManagerDao.addChannelDetail(vo)
以上两个调用,应该是执行完第一个后,你的连接断开了,当执行第二个时,又重新打开了连接,本质上就是两个session,所以不能rollback。
解决方案三:
service层手动添加事务控制代码试一下
解决方案四:
引用1楼wmxcn2000的回复:
ghManChannelManagerDao.addChannelInfo(vo)ghManChannelManagerDao.addChannelDetail(vo)以上两个调用,应该是执行完第一个后,你的连接断开了,当执行第二个时,又重新打开了连接,本质上就是两个session,所以不能rollback。
是的,日志显示的conn编码确实不一样,那应该如何做呢,新手不懂,望指教,谢谢
解决方案五:
引用2楼pengdott的回复:
service层手动添加事务控制代码试一下
能否给个例子,谢谢
解决方案六:
高手在哪里?
解决方案七:
手动添加事物控制代码,添加注解,在需要事物控制的方法上添加事物控制注解