在spring事务中设置事务提交。。

解决方案 »

  1.   

    使用spring的aop,进行方法拦截,你的事务设置一定要打开“写”模式,才可以进行数据库写操作,默认是“读”模式,写操作将被忽略,不要用session.commit(),会打破整个事务体系的
      

  2.   

    我 最后用  Session   session   =   getHibernateTemplate().getSessionFactory().openSession();   
    getHibernateTemplate().save(areaBo);

            Transaction   tx   =   session.beginTransaction();           tx.commit();   
            session.close();解决的问题``请问下  在bean.xml里面设置的  方法拦截 怎么写?接触Spring不是很久都是自己在琢磨``
    <!--定义默认的事务策略-->
      <bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
        <property name="transactionAttribute"><value>PROPAGATION_REQUIRED</value></property>
      </bean>

      <!--定义事务管理的拦截器-->
      <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
          <ref bean="transactionManager"/>
        </property>
        <property name="transactionAttributeSource">
          <ref local="transactionAttributeSource"/>
        </property>
      </bean>
      
       <!--定义动态的事务代理通过bean的名称-->
      <bean id="autoProxyPlane" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="interceptorNames">
          <list>
            <value>transactionInterceptor</value>
          </list>
        </property>
        <property name="beanNames">
          <list>
            <value>accountImpl</value>
             <value>iuserImpl</value>
          </list>
        </property>
      </bean>
      类似与这样吗?