以下是我的配置事务管理器,问题是在同一个类中只有saveOrUpdateAll方法可以提交事务,update ,delete,insert方法都不可以提交事务,请高手求救啊  好郁闷  遇到这样问题   我声明的方法都没错啊  为什么不能提交呢<?xml version="1.0" encoding="UTF-8"?><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">
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>           

<!-- 配置事务管理器 -->
<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="insert*" propagation="REQUIRED"/>
<tx:method name="saveOrUpdateAll*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.service.Impl.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>

解决方案 »

  1.   

    我用的是HibernateTemplate来对数据库操作的
      

  2.   

    <tx:method name="insert*" propagation="REQUIRED"/> 
    <tx:method name="saveOrUpdateAll*" propagation="REQUIRED"/> 
    <tx:method name="update*" propagation="REQUIRED"/> 
    <tx:method name="delete*" propagation="REQUIRED"/> 
    <tx:method name="*" read-only="true"/> 
    方法名写对了吗?
    有没有报错误啊?
      

  3.   

    方法名对啊  我很认真检查过啦    也没有报错  tomcat后台都打印有操作的hql语句  但就是不能插入或更新到数据库  只有saveOrUpdateAll方法可以提交事务
      

  4.   

    下面是我的service层实现类代码
    package com.service.Impl;import java.io.Serializable;
    import java.util.Collection;
    import java.util.List;
    import java.util.Set;import com.abstr.service.AbstrServiceOrdersDetail;
    import com.dao.Interface.IBaseDao;
    import com.model.Orders;
    import com.model.OrdersDetail;
    import com.service.Interfacce.IBaseService;public class OrdersDetailServiceImpl extends AbstrServiceOrdersDetail  {
        private IBaseDao ibaseOrdersDetailDao;
        private IBaseDao<Orders,Integer> ordersDao; public void delete(OrdersDetail entiyObj) {
    // TODO Auto-generated method stub
                
    } public List findAll() {
    // TODO Auto-generated method stub
    return null;
    } public OrdersDetail findById(Integer id) {
    // TODO Auto-generated method stub
    return (OrdersDetail)ibaseOrdersDetailDao.findById(id);
    } public Integer insert(OrdersDetail entiyObj) {
    // TODO Auto-generated method stub

    return ibaseOrdersDetailDao.insert(entiyObj);
    } public void update(OrdersDetail entiyObj) {
    // TODO Auto-generated method stub
    ibaseOrdersDetailDao.update(entiyObj);
    }
    // public void saveOrUpdateAll(Collection<OrdersDetail> c, Object obj)
    public void saveOrUpdateAll(Collection<OrdersDetail> c,Object orders){

    for(OrdersDetail detail:c){
    detail.setOrders((Orders)orders);

    }
    ordersDao.insert((Orders)orders);
    ibaseOrdersDetailDao.saveOrUpdateAll(c);//以多的一端插入

    }
    public IBaseDao getIbaseOrdersDetailDao() {
    return ibaseOrdersDetailDao;
    } public void setIbaseOrdersDetailDao(IBaseDao ibaseOrdersDetailDao) {
    this.ibaseOrdersDetailDao = ibaseOrdersDetailDao;
    } public IBaseDao<Orders, Integer> getOrdersDao() {
    return ordersDao;
    } public void setOrdersDao(IBaseDao<Orders, Integer> ordersDao) {
    this.ordersDao = ordersDao;
    } }
      

  5.   

    真是不明白啊    在我不经意的调试下   发现一个现象
    就是执行service层update方法后   数据库不会更新
    但是再执行service层saveOrUpdateAll方法后  前面的执行的update方法数据库里的数据立刻更新 同时也更新saveOrUpdateAll后的数据  
      

  6.   

    是不是的hibernate的三个状态有关系呀!
      

  7.   

    saveOrUpdateAll前面的没有commit!