applicationContext.xml 文件
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
 <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">    
            <property name="transactionManager" ref="transactionManager"/>
            <property name="transactionAttributes">   
                <props>   
<prop key="insert*">PROPAGATION_REQUIRED,-RemoteException</prop>
<prop key="update*">PROPAGATION_REQUIRED,-RemoteException</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
                </props>   
            </property>   
        </bean>    
        
        <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">    
                <property name="beanNames">   
                    <value>*Service,*Dao</value>   
                </property>   
                <property name="interceptorNames">    
                        <list>    
                               <value>transactionInterceptor</value>    
                        </list>    
                </property>    
        </bean>    
  
        <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">    
          <property name="transactionInterceptor" ref="transactionInterceptor"/>    
        </bean> actionpublic String insertInfo()throws Exception  {
if (this.userService.checkName(userInfo.getUserName())) {
this.addActionError("该用户名已经存在,请重新输入");
this.userInfo.setUserName("");
return "add";
} else {
this.userService.insertUserInfo(userInfo);
            this.organManageService.insertOrganInfo(organInfo);
return "listpage";
} }
第二个添加语句是错误,但是事务没有回滚,第一条语句还是添加到了数据库中。
第一次配置事务,不知道该怎么解决??

解决方案 »

  1.   

    只会另一种管理 事务 的方法。。<!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>    

    <!-- 事务的传播特性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="del*" propagation="REQUIRED" />
    <tx:method name="up*" propagation="REQUIRED"/>
    <tx:method name="*" read-only="true"/>
    </tx:attributes>
    </tx:advice>

    <!-- 那些类那些方法使用事务 -->
    <aop:config>
    <aop:pointcut id="allManagerMethod" expression="execution(* com.service.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
    </aop:config>不知道能不能帮上忙,这种方法需要在  在表头 那里加 很多  东西,如:
    <beans xmlns="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/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
      

  2.   

    2楼的是hibernate的事务配置。不知道你说的表头指的是什么?
      

  3.   

    <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">
    PROPAGATION_REQUIRED,-RemoteException
    </prop>
    <prop key="update*">
    PROPAGATION_REQUIRED,-RemoteException
    </prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    <bean
    class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
    <property name="transactionInterceptor"
    ref="transactionInterceptor" />
    </bean> <bean
    class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="beanNames">
    <list>
    <value>userService</value> </list>
    </property>
    <property name="interceptorNames">
    <list>
    <value>transactionInterceptor</value>
    </list>
    </property>
    </bean>