请问在Struts+Spring+Hibernate架构下,在Spring的配置文件applicationContext.xml里如何配置多表更新的事务管理? 多表和单表没有区别,你看一下spring的文档配上就可以了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 貌似只要对这个save方法附加事务管理就行了,spring的事务应该是业务层的事务管理,配置事务的代码到处都是,自己搜搜看 例如我的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()方法是分别往两张表插入数据,按照我现在的配置,是否能实现保证这两张表的数据同时更新或失败呢? 应该可以保证,你的粒度控制在service的方法 声明型事务管理较为合理的是将事务配置在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>注意红色部分 没变成红色。注意(* org.sshdemo.service.*.*(..) 请教一个关于多对多关系与数据库设计的问题 求大牛帮忙优化一段程序 遇到问题请高手指教 请高手来帮我看一下,谢谢! 在Axis中使用WSDL2Java工具的问题,急! struts2 标签 如果页面上没有html和body的话无法显示值嘛? 如何解析xml并导到sql数据库?求救阿! 我需要继承HttpSession吗? 256M的小本上能装weblogic 或 websphere能跑的动吗??!! snmp4j如何采集交换机的端口信息 关于搜索页码分页显示!急,请帮帮忙! 请教在windows server2003上apache安装的问题!
<!-- 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()方法是分别往两张表插入数据,按照我现在的配置,是否能实现保证这两张表的数据同时更新或失败呢?
声明型事务管理较为合理的是将事务配置在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>注意红色部分