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

原文地址:https://www.cnblogs.com/fingerboy/p/5287034.html