標籤: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 applyImportSourcesINFO: HHH000476: Executing import script ‘org.hiber[email protected]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!