hibernate常见问题?

1、

  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

  hibernate4版本<prop key="hibernate.current_session_context_class">thread</prop>---》获取当前会话会导致如下结果:

  异常信息:org.hibernate.HibernateException: save is not valid without active transaction

  hibernatenate4版本,取消<prop key="hibernate.current_session_context_class">thread</prop>会导致如下结果:

  异常信息: Already value [org.springframework.orm.hibernate5.SessionHolder@779dfe55] for key

  [org.hibernate.internal.SessionFactoryImpl@502f8b57]  bound to thread [main]

  

  解决:将hibernate版本改为hibernate5版本,hibernate可以直接使用getCurrentSession获取当前会话!

 

原文地址:https://www.cnblogs.com/xcggdd/p/6891789.html