今天在整合Hibernate与Spring时候,遇到了一个异常:getHibernateFlushMode is not valid without active transaction;
在确认代码没有错误的情况下,百度发现了一条解决方法:
把hibernate的 hibernate.current_session_context_class 这项属性去掉!否则事务是不起效的!!也就是hibernate配置文件的<property name="current_session_context_class">thread</property> 或者Spring配置文件的 <prop key="hibernate.current_session_context_class">thread</prop>
至于原因,下面这位大神做了详细的解释。
https://blog.csdn.net/naruto_Mr/article/details/48085191