No Session found for current thread

来源:互联网 发布:java初级招聘北京 编辑:程序博客网 时间:2024/05/22 08:28

DAO中要用getCurrentSession来获得session的话报No Session found for current thread

解决办法:

dao方法不要openSession,要获取当前session,不要关闭session:
Session session=sessionFactory.getCurrentSession()
dao只需要直接注入sessionFactory,不需要继承hibernatedaosupport之类的;
另外,需要service层一定要配置好声明事务!

0 0
原创粉丝点击