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的工厂.有可能持有一个可选的数据缓存可以进程级别或者群级别保存可以在事务中 ...
随机推荐
- 51ak带你看MYSQL5.7源码1:main入口函数
从事DBA工作多年 MYSQL源码也是头一次接触 尝试记录下自己看MYSQL5.7源码的历程 目录: 51ak带你看MYSQL5.7源码1:main入口函数 51ak带你看MYSQL5.7源码2:编译 ...
- SqlSever数据库实践周
资源下载 进行了为期5天的数据库设计,虽然以前用过数据库,但是这一次是使用书上规范的设计流程设计的数据库,感觉有必要记录一下,希望对其他人有帮助. 我的收获:在这个博客中会体现到我的收获,对于将要进行 ...
- 笔记:Hibernate 数据库方言表
关系数据库 方言 DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS/ ...
- 关于mongodb按照字段模糊查询方法
模糊查询:tname包含某个关键字测试' cd /opt/soft/mongodb/bin ./mongo --host 192.168.0.1 --port 17017 test db.test ...
- 【Python】排列组合itertools & 集合set
■itertools 利用python的itertools可以轻松地进行排列组合运算 itertools的方法基本上都返回迭代器 比如 •itertools.combinations('abcd',2 ...
- 理解HDFS
综述 当数据集的大小超过一台独立的物理计算机的存储能力时,就有必要对它进行分区并存储到若干台单独的计算机上.HDFS是hadoop的主要分布式存储系统,一个HDFS集群主要包括NameNode用来管理 ...
- android中shape属性大全
出处:http://kofi1122.blog.51cto.com/2815761/521605
- freemarker 类型转换
操作字符串函数 1. substring(start,end)从一个字符串中截取子串 start:截取子串开始的索引,start必须大于等于0,小于等于endend: 截取子串的长度,end必须大 ...
- 生产者/消费者问题的多种Java实现方式
实质上,很多后台服务程序并发控制的基本原理都可以归纳为生产者/消费者模式,而这是恰恰是在本科操作系统课堂上老师反复讲解,而我们却视而不见不以为然的.在博文<一种面向作业流(工作流)的轻量级可复用 ...
- MySQL的学习记录(3.31更新)
MySQL的学习记录(3.31更新) 0x00 安装及配置 Windows 1.首先官网下载(https://dev.mysql.com/downloads/mysql/) ps:不想官网下载的可以到 ...