Hibernate 异常 —— No CurrentSessionContext configured
在使用 SessionFactory 的 getCurrentSession 方法时遇到如下异常 “No CurrentSessionContext configured ”
原因是:
在hibernate.cfg.xml文件中缺少如下属性设置:hibernate.current_session_context_class
修正方法如下:
如果是Web项目,则在hibernate.cfg.xml中加入这句话:
<property name="hibernate.current_session_context_class">jta</property>
如果是Java Application,则这样设置:
<property name="hibernate.current_session_context_class">thread</property>
P.S:如果hibernate.cfg.xml这个配置文件是从其他项目或者Hibernate的文档上 Copy-修改,这个属性 hibernate.current_session_context_class 是有的。
笔者之所以遇到这样的问题,是使用了Hibernate的反向工程,自动生成的配置文件。
Hibernate 异常 —— No CurrentSessionContext configured的更多相关文章
- Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!
Hibernate版本5.2.9 获取Session的方式是sessionFactory.getCurrentSession(); 比较老一些的版本使用的是sessionFactory.openSes ...
- hibernate报错org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.internal.Ses ...
- org.hibernate.HibernateException: No CurrentSessionContext configured!
hibernate可以通过两种方式获得Session: getCurrentSession() 和openSession(). 当通过getCurrentSession()方法时,需要在 hibern ...
- Hibernate中报错org.hibernate.HibernateException: No CurrentSessionContext configured!
报错信息如下: 解决方法: 问题原因是getCurrentSession()出现了问题 在hibernate.cfg.xml(hibernate的核心配置文件)文件中加入下列代码: <prope ...
- No CurrentSessionContext configured 异常解决
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext conf ...
- Hibernate 异常总结
异常一 异常一 异常描述: Sax解析异常:cvc-复杂的类型,发现了以元素maping开头的无效内容,应该是以 ‘{“http://www.hibernate.org/xsd/orm/cfg“:pr ...
- 依据错误原理解决Hibernate执行出现No CurrentSessionContext configured!错误
(1)异常信息例如以下: 严重: Servlet.service() for servlet action threw exception java.lang.RuntimeException: &l ...
- 转 使用Hibernate操作数据库时报:No CurrentSessionContext configured! 异常
没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:1.本地事务<property name=&q ...
- Hibernate 异常提示_1
INFO: HHH000041: Configured SessionFactory: null九月 15, 2016 12:29:35 上午 org.hibernate.engine.jdbc.co ...
随机推荐
- 二分--1043 - Triangle Partitioning
1043 - Triangle Partitioning PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: ...
- vertical sync
these days, I am compelting vertical sync https://msdn.microsoft.com/zh-cn/library/windows/desktop/b ...
- html5离线存储
为了提升Web应用的用户体验,我们在做网站或者webapp的时候,经常需要保存一些内容到本地.例如,用户登录token,或者一些不经常变动的数据. 随着HTML5的到来,出现了诸如AppCache.l ...
- logback日志配置文件代码示例
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true&q ...
- Sqli-labs less 25a
Less-25a 不同于25关的是sql语句中对于id,没有''的包含,同时没有输出错误项,报错注入不能用.其余基本上和25示例没有差别.此处采取两种方式:延时注入和联合注入. http://127. ...
- JobClient学习------作业提交与初始化
public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); ...
- POJ3469 Dual Core CPU(最小割)
题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...
- ACE 1.1.9 发布,开源云端代码编辑器
点这里 ACE 1.1.9 发布,开源云端代码编辑器 oschina 发布于: 2015年04月06日 (1评) 分享到: 收藏 +25 4月18日 武汉 源创会开始报名,送华为开发板 ACE ...
- POJ 2140
#include<iostream> #include<stdio.h> using namespace std; int main() { int num; int i; i ...
- Codeigniter 利用加密Key(密钥)的对象注入漏洞
http://drops.wooyun.org/papers/1449 原文链接:http://www.mehmetince.net/codeigniter-object-injection-vuln ...