Hibernate:没有配置CurrentSessionContext

jco*_*lin 25 hibernate liferay

我一直得到一个:

HibernateException:没有配置CurrentSessionContext!

在我的代码中.返回的其他搜索的唯一信息是罪魁祸首:

<property name="current_session_context_class">thread</property>
Run Code Online (Sandbox Code Playgroud)

在我的hibernate.cfg.xml中.我在我的hibernate.cfg.xml文件中有这个,我在Tomcat 6中运行它.有没有人知道其他可能的原因?

Ian*_*las 25

我相信你需要将你的current_session_context_class设置为一个实际的类...我为我配置了hibernate.cfg.xml,如下所示:

<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
Run Code Online (Sandbox Code Playgroud)

上面的代码用于mySql数据库,但我认为数据库对于上述属性的类型并不重要

希望这可以帮助

  • @javaloper,如果你只是说有一个拼写错误就会很好:"hibnerate"而不是"hibernate".我想知道为什么你在评论中发布了相同的内容. (3认同)

Jac*_*uka 11

这两个都在Hibernate 4+中工作:

<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.ThreadLocalSessionContext</property>
Run Code Online (Sandbox Code Playgroud)

在早期版本的Hibernate中,它使用了org.hibernate.context.ThreadLocalSessionContext(如其他答案所示).