Spring整合hibernate-关于事物配置(无法回滚)解决方法
阅读
在service层,保存用户的时候同时记录日志,在记录日志的DAO层抛出RuntimeException,事物无法回滚,用户和日志都成功插入到数据库,并没有回滚,求解?事物配置哪里出问题?
- Java code
<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>net.sourceforge.jdbclogger.JdbcLoggerDriver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/spring</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <bean id="userDAO" class="com.dao.impl.UserDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="logDAO" class="com.dao.impl.LogDAOImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="userService" class="com.service.impl.UserServiceImpl"> <property name="userDAO" ref="userDAO"></property> <property name="logDAO" ref="logDAO"></property> </bean> <bean id="logService" class="com.service.impl.LogServiceImpl"> <property name="logDAO" ref="logDAO"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>user.hbm.xml</value> <value>log.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="current_session_context_class">thread</prop> </props> </property> <!-- <property name="configLocation" value="classpath:hibernate.cfg.xml"/> --> </bean> <!-- 事物管理 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <list> <value>*Service</value> </list> </property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean> </beans>阅读上一篇:string.split("")无法用$进行分割解决思路 下一篇:返回列表