你没有事务,无法产生 session 与当前线程绑定

解决方案 »

  1.   

    用getCurrentSession()要配置一个<property name="current_session_context_class">thread</property>的
      

  2.   

    Trying to add the following in your hibernate config should also help:<property name="current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
      

  3.   

    谢谢各位,问题已经解决, 方法如下,希望可以给遇到同样问题的同学做一个参考:在dao层直接用hibernateTemplate去操作数据,而不去取session,两者的用法几乎一样, 这样问题就轻松解决了, 因为用hibernateTemplate 工具类的话session的关闭打开就全部交给spring了, 不用自己手动控制, ;例如://根据id取对象
    public  User find(int user_id){
    HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
    User user = (User)hibernateTemplate.get(User.class,user_id);
    return user;

    }这是一小段示例, 已经测试过, 确实是正确可行的。