BOpublic class ElectronicScaleComeBO{
public void executeSave(Come come,Account account){ //整体是一个事物
saveCome(come);
updateAccount(account);
Detail detail = createDetail(come,account);//创建一个Detail 对象
saveDetail(detail);
} private void saveCome(Come come).....保存1
private void updateAccount(Account acount)...保存2
private void saveDetail(Detail detail).........保存3 private Detail createDetail(Come come ,Account acount){ //明细中会取come和account一些值.
Detail detail = new Detail();
detail.setxxx(come.getxxx);
detail.setxxx(account.getxxx);
return detail;
}
}出了个很怪的问题``Come、Detail都保存成功了但updateAccount取没被修改
如果把Detail detail = createDetail(come,account);//创建一个Detail 对象
saveDetail(detail);给去掉updateAccount就成功了!
搞了一天都没明白谁能指点指点啊 !事物配置<bean id="electronicscaleBOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManage"></property>
<property name="target" ref="electronicscalecomebo"></property>
<property name="transactionAttributes">
<props>
<prop key="execute">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
public void executeSave(Come come,Account account){ //整体是一个事物
saveCome(come);
updateAccount(account);
Detail detail = createDetail(come,account);//创建一个Detail 对象
saveDetail(detail);
} private void saveCome(Come come).....保存1
private void updateAccount(Account acount)...保存2
private void saveDetail(Detail detail).........保存3 private Detail createDetail(Come come ,Account acount){ //明细中会取come和account一些值.
Detail detail = new Detail();
detail.setxxx(come.getxxx);
detail.setxxx(account.getxxx);
return detail;
}
}出了个很怪的问题``Come、Detail都保存成功了但updateAccount取没被修改
如果把Detail detail = createDetail(come,account);//创建一个Detail 对象
saveDetail(detail);给去掉updateAccount就成功了!
搞了一天都没明白谁能指点指点啊 !事物配置<bean id="electronicscaleBOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManage"></property>
<property name="target" ref="electronicscalecomebo"></property>
<property name="transactionAttributes">
<props>
<prop key="execute">PROPAGATION_REQUIRED</prop>
</props>
</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="update*" propagation="REQUIRED"/> //!!!!!!!!!!!!!!!!!
<tx:method name="attach*" propagation="REQUIRED"/>
<tx:method name="merge*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<bean id="electronicscaleBOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManage"></property>
<property name="target" ref="electronicscalecomebo"></property>
<property name="transactionAttributes">
<props>
<prop key="execute*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>不好意思最贴错了!修改如上
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!-- 以AspectJ方式 定义AOP-->
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.gotopweb.sysbase..*Manager.*(..))" advice-ref="txAdvice"/> <!-- 系统模块的声明式表达式 -->
<aop:advisor pointcut="execution(* com.gotopweb.demo..*ServiceImpl.*(..))" advice-ref="txAdvice"/> <!-- 示例DEMO模块的声明式事务表达式 -->
</aop:config> <!-- 基本事务定义,使用transactionManager作事务管理,默认get*方法的事务为readonly -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" read-only="false" rollback-for="Throwable"/>
</tx:attributes>
</tx:advice>
saveCome(come);
//这里拿到hibernate的事务
//不知道你这里能操作session不
Transaction t = session.beginTransaction();
updateAccount(account);
t.commit();//如果能更新就说明是事务问题啦
Detail detail = createDetail(come,account);//创建一个Detail 对象
saveDetail(detail);
}