多表和单表没有区别,你看一下spring的文档配上就可以了。

解决方案 »

  1.   

    貌似只要对这个save方法附加事务管理就行了,spring的事务应该是业务层的事务管理,配置事务的代码到处都是,自己搜搜看
      

  2.   

    例如我的applicationContext.xml里关于用户帐户的事务管理配置如下:
    <!-- 2、用户帐户管理对象 业务对象配置 -->
    <bean id="accountService"  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property>
       <property name="proxyTargetClass">
      <value>true</value>
    </property>
    <property name="target">
    <ref local="accountTarget" />
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="Add*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <!-- 用户帐户管理对象     业务对象实现配置 accountTarget primary business object implementation -->
    <bean id="accountTarget" class="com.linkersoft.lkweblearning.business.AccountServiceImpl">
       <property name="userAccount"><ref local="UseraccountDAO"/></property>
       <property name="userAccountDetail"><ref local="UseraccountdetailDAO"/></property>
    </bean> 在业务对象accountService里的AddCount()方法里,同时调用了userAccount.Insert()方法和userAccountDetail.insert()方法,这个两个Insert()方法是分别往两张表插入数据,按照我现在的配置,是否能实现保证这两张表的数据同时更新或失败呢?
      

  3.   

    应该可以保证,你的粒度控制在service的方法
      

  4.   


    声明型事务管理较为合理的是将事务配置在service层。有2种方法,标记配置和在applicationContext中配置事务拦截器。具体做法参考spring的referance。下给出一个简单的配置在应用程序上下问的代码:
    <!-- JPA Transaction manager :JPA事务控制设置-->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="dataSource" ref="dataSource"/>
    </bean> <aop:config>
    <aop:pointcut id="crudMethods" expression="execution(* org.sshdemo.service.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="crudMethods"/>
    </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="save" propagation="REQUIRED"/>
    <tx:method name="update" propagation="REQUIRED"/>
    <tx:method name="delete" propagation="REQUIRED"/>
    </tx:attributes>
    </tx:advice>注意红色部分
      

  5.   

    没变成红色。注意(* org.sshdemo.service.*.*(..)