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>
经调试,问题解决了。
Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!的更多相关文章
- hibernate报错org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.internal.Ses ...
- Hibernate中报错org.hibernate.HibernateException: No CurrentSessionContext configured!
报错信息如下: 解决方法: 问题原因是getCurrentSession()出现了问题 在hibernate.cfg.xml(hibernate的核心配置文件)文件中加入下列代码: <prope ...
- org.hibernate.HibernateException: No CurrentSessionContext configured!
hibernate可以通过两种方式获得Session: getCurrentSession() 和openSession(). 当通过getCurrentSession()方法时,需要在 hibern ...
- 转 使用Hibernate操作数据库时报:No CurrentSessionContext configured! 异常
没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:1.本地事务<property name=&q ...
- No CurrentSessionContext configured 异常解决
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext conf ...
- Hibernate 异常 —— No CurrentSessionContext configured
在使用 SessionFactory 的 getCurrentSession 方法时遇到如下异常 “No CurrentSessionContext configured ” 原因是: 在hibern ...
- 依据错误原理解决Hibernate执行出现No CurrentSessionContext configured!错误
(1)异常信息例如以下: 严重: Servlet.service() for servlet action threw exception java.lang.RuntimeException: &l ...
- 第三章Hibernate关联映射
第三章Hibernate关联映射 一.关联关系 类与类之间最普通的关系就是关联关系,而且关联是有方向的. 以部门和员工为列,一个部门下有多个员工,而一个员工只能属于一个部门,从员工到部门就是多对一关联 ...
- Hibernate(三)结构-配置文件-实体映射及配置文件
一.体系结构 SessionFactory:属于单一数据库的编译过的映射文件的一个线程安全的,不可变的缓存快照.Session的工厂.有可能持有一个可选的数据缓存可以进程级别或者群级别保存可以在事务中 ...
随机推荐
- Microsoft AI - Custom Vision
概述 前几天的 Windows Developer Day 正式发布了 Windows AI Platform,而作为 Windows AI Platform 的模型定义和训练,更多还是需要借助云端来 ...
- js中==和===区别
简单来说: == 代表相同, ===代表严格相同, 为啥这么说呢, 这么理解: 当进行双等号比较时候: 先检查两个操作数数据类型,如果相同, 则进行===比较, 如果不同, 则愿意为你进行一次类型转换 ...
- 给定n,求1/x + 1/y = 1/n (x<=y)的解数~hdu-1299~(分解素因子详解)
链接:https://www.nowcoder.com/acm/contest/90/F来源:牛客网 题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均为正整 ...
- 利用whoosh对mongoDB的中文文档建立全文检索
1.建立索引 #coding=utf-8 from __future__ import unicode_literals __author__ = 'zh' import sys,os from wh ...
- java中有关流操作的类和接口
一.java操作l流有关的类和接口 1.File 文件类 2.RandomAccessFile 随机存储文件类 3.InputStream 字节输入流 4.OutputStream 字节输出流 5.R ...
- Matlab绘图基础——图形修饰处理(入门)
引入--标题.色条.坐标轴.图例等 例一: set(groot,'defaultAxesLineStyleOrder','remove','defaultAxesColorOrder','remove ...
- 实现win的on程序数据更新
枚举是一组描述性的名称定义一组有限的值,不包含方法对可能的值进行约束枚举是一组指定的常数,对可能的值进行约束枚举使用时直观方便.更易于维护 pictureBox控件属性名称 说明image ...
- “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift
使用cocopod导入第三方swift包后,编译报以下错误: The "Swift Language Version" (SWIFT_VERSION) build setting ...
- Java基础笔记(7)----三个修饰符
abstract抽象 方法 抽象方法:abstract修饰的方法,只有声明 而没有方法的实现(连{}都没有). 语法:修饰符 返回值类型 方法名(形参列表); 注意:抽象方法 必须定义在 抽象类中. ...
- [日常] 最近的一些破事w...
更新博文一篇以示诈尸(大雾 (其实只是断了个网然后就彻底失踪了一波w...连题解都没法写了QAQ) $ \tiny{诈尸的实际情况是老姚提前走还把十一机房门锁了然而钥匙在联赛的时候就还了于是并不能进去 ...