spring整合hibernate的时候报异常org.hibernate.HibernateException: createQuery is not valid without active transaction


  在整合Spring4+hibernate4时候,当代码执行到dao中CRUD操作时,报了一个异常,

org.hibernate.HibernateException: createQuery is not valid without active transaction ...

  因为我用到的是session是通过sessionFactory.getCurrentSession()方法获得到的,这个session是和事务(transaction)绑定的,这个异常是告诉我,session的操作没有在一个活动的事务下进行,可是我检查了spring配置文件,是没有错误的,,试了很多种解决方法都没有成功,最后发现了问题,把hibernate.cfg.xml:中的一句代码:hibernate.current_session_context_class删掉之后,就能正常运行了.

  详细原因的分析,这篇博文写的不错.http://blog.csdn.net/yinjian520/article/details/8666695

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM