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>

    经调试,问题解决了。

  • 相关阅读:
    Windows抓取密码总结
    PHP一句话简单免杀
    Shiro反序列化利用
    windows绕过杀软添加账户密码
    java基础-操作符
    微信小程序开发笔记(十一)--输入框计数
    微信小程序开发笔记(十)--多选标签效果
    微信小程序开发笔记(九)--单选标签效果
    微信小程序开发笔记(八)--路由跳转
    proxy_pass 代理转发
  • 原文地址:https://www.cnblogs.com/yy3b2007com/p/6714112.html
Copyright © 2011-2022 走看看