这个问题的出现关系到getcurrentSessionFactory和opencurrentSessionFactory这两个问题的,解决的方法是:
1.获得session的时候你就用openSession就行了。
2如果用到getCurrenctSession()的话,你就在sessionFactory 那个bean中配置
<prop key="hibernate.current_session_context_class">
thread
</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory</prop>
,目前还不理解这个问题。。。先知道怎么解决
1.getCurrentSession()是必须提交事务的。所以呢,你在用到session.getCurrentSession()的这个方法一定是要配置声明式事务管理。具体的声明式管理可以去网上google一下就知道怎么配置了。
2.openSession()恰恰是与以上的方法想法,它不需要提交事务。但是他的资源必须手动关闭。