码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!

时间:2017-04-15 14:52:33      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:inf   nts   com   cto   script   .exe   name   property   rip   

Hibernate版本5.2.9

获取Session的方式是sessionFactory.getCurrentSession();

比较老一些的版本使用的是sessionFactory.openSession()是不管任何情况都重新开启一个Session。

从两者却别来说getCurrentSession();相对的增加了一个判断,在有Session的情况下就会直接去调用,没有session的话才会创建。比openSession()要好一点。

但是,目前却遇到了问题:

四月 15, 2017 1:38:33 下午 org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script ‘org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@4ebea12c‘
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:454)
    at com.dx.hibernate5.test.HelloWord.main(HelloWord.java:43)

网上搜索了一下,找到了解决问题的方案:

1、如果是Hibernate集成了JBoss的情况下,需要在*.cfg.xml配置文件中新增配置:

<property name="hibernate.current_session_context_class">jta</property>

2、如果是不继承的话,需要在*.cfg.xml配置文件中新增配置:

<property name="hibernate.current_session_context_class">thread</property>

经调试,问题解决了。

 

Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!

标签:inf   nts   com   cto   script   .exe   name   property   rip   

原文地址:http://www.cnblogs.com/yy3b2007com/p/6714112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!