User user = (User)this.hibernateTemplate.load(User.class, id);
    System.out.println(user.getLoginName()+"--------------delete----------hibernatetemplate:"+this.hibernateTemplate);
    this.hibernateTemplate.delete(user);
    System.out.println("-----------------------------delete");
在执行了this.hibernateTemplate.delete(user);没发出HQL语句,也没有任何反应,数据还是没删除成功

解决方案 »

  1.   

    设置一下断点,观察一下!控制台如果没有打印出你的s.o.pln()的信息,表示那个方没有执行到
      

  2.   


    误人子弟了!不是提交事务才行,在spring封装的hibernate中,每执行一次save(),delete()....这类的操作,都要执行这句 session.flush();
    你说的提交事务,其实也是执行了session.flush()的
      

  3.   

    spring的配置文件要有对事物处理的配置,不然在代码只有手工处理
      

  4.   

    加上试试
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="remove*" propagation="REQUIRED" />
    <tx:method name="modify*" propagation="REQUIRED" />
    <tx:method name="*" propagation="NOT_SUPPORTED"
    read-only="true" />
    </tx:attributes>
    </tx:advice> <aop:config>
    <aop:pointcut
    expression="execution(* com.ambow.service.*.*(..))" id="AllMethod" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="AllMethod" />
    </aop:config>
      

  5.   

    用了hibernateTemplate的话,是spring帮你管理事务...按道理是应该可以删除的
      

  6.   

    建议还是debug吧!
       这种事debug 是最有效果的。 
      

  7.   

    大吓们,我已debug了,但是执行了this.hibernateTemplate.delete(user);这句一点反应也没有,没有打印任何语句<bean id="baseTxProxy" lazy-init="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>

    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    这些我也加了
      

  8.   

    junit测试类也通过了,可以把数据库里的数据删掉,也发出了HQL语句,就是用这页面来删执行到这一句的时候像没事发生一样
           上面的user查出来是有对象的,就是执行delete时没有情况发生,也不报错,
     求大虾们帮忙!!!      急
      

  9.   

    你的这段代码没有问题,debug一下看看执行到哪里,看看有没有执行到这个方法,然后打印一下你的那个id获得的对象user看是否存在 
      

  10.   

    楼上的,代码已经全部执行,对象也拿出来了,就是执行this.hibernateTemplate.delete(user)这一句没有任何的反应
      

  11.   

    楼主,你用SPRING容器管理事务的话 删除信息要先调用get(Class,id)方法
    public boolean deleteInfo(int id){
    boolean flag = false;
    try {
    T t= (T)this.getHibernateTemplate().get(cls,id);
    if(t!=null){
    this.getHibernateTemplate().delete(t);
    flag = true;
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return flag;
    }
      

  12.   


    先调用get()方法再删除的话会把session缓存中的记录也删除了的,如果只想删除数据库中的记录直接delete()可以吗?
    我是小菜鸟,正在学习JAVA相关内容,还望指点.