zoukankan      html  css  js  c++  java
  • Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!

    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>

    经调试,问题解决了。

  • 相关阅读:
    转移到新的个人独立博客。
    hdu5618 (三维偏序,cdq分治)
    平衡树维护动态凸包
    poj1986 LCA
    hdu2586 LCA
    LCA最近公共祖先 ST+RMQ在线算法
    hdu 3401 单调队列优化DP
    【转】单调队列优化DP
    CodeForces 548D 单调栈
    hdu3530 单调队列
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/6714112.html
Copyright © 2011-2022 走看看