解决方案 »

  1.   

    事物没有提交吧,flush()一下试试
      

  2.   

    这是我的事务配置:
    <bean id"txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
     <property name="sessionFactory" ref="sessionFactory">
    </bean>
    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
      <tx:method name="save*"/>
      <tx:method name="update*"/>
      <tx:method name="delete*"/>
      <tx:method name="*" propagation="supports"/>
    </tx:attributes>
    </tx:advice>
    <aop:config proxy-target-class="true">
      <aop:advisor pointcut="execution(* com.demos.service..*.*Impl.* (..))"
    advice-ref="txAdvice"/>
    </aop:config>
    我的事务加在了service层,但只有查询和插入数据能发出sql语句,在web.xml中我也把OpenSessionInView这个类配置在了struts2的拦截器之前,可还是没有用
      

  3.   

    我的dao层相关代码如下
    private SessionFactory sessionFactory;
    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory){this.sessionFactory=sessionFactory;}
    public Session getCurrentSession(){
      return this.sessionFactory.getCurrentSession();
    }
    public void update(User user){
     this.getCurrentSession().update(user);
    }
    public void delete(int id){
    this.getCurrentSession().delete(findUser(id));
    public User findUser(int id){
    return (User)this.getCurrentSession().load
    (User.class,id);}
      

  4.   

    <!-- 事务的传播特性 -->
    <tx:advice id="txadvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="create" propagation="REQUIRED" />

     <!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->
    <tx:method name="*" propagation="REQUIRED" read-only="true" />
    </tx:attributes>
    </tx:advice>试试这样呢?那个create是创建的方法create(),然后在dao里面用getSession().save(user);方法。。