在使用 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的更多相关文章

  1. Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!

    Hibernate版本5.2.9 获取Session的方式是sessionFactory.getCurrentSession(); 比较老一些的版本使用的是sessionFactory.openSes ...

  2. hibernate报错org.hibernate.HibernateException: No CurrentSessionContext configured!

    org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.internal.Ses ...

  3. org.hibernate.HibernateException: No CurrentSessionContext configured!

    hibernate可以通过两种方式获得Session: getCurrentSession() 和openSession(). 当通过getCurrentSession()方法时,需要在 hibern ...

  4. Hibernate中报错org.hibernate.HibernateException: No CurrentSessionContext configured!

    报错信息如下: 解决方法: 问题原因是getCurrentSession()出现了问题 在hibernate.cfg.xml(hibernate的核心配置文件)文件中加入下列代码: <prope ...

  5. No CurrentSessionContext configured 异常解决

    Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext conf ...

  6. Hibernate 异常总结

    异常一 异常一 异常描述: Sax解析异常:cvc-复杂的类型,发现了以元素maping开头的无效内容,应该是以 ‘{“http://www.hibernate.org/xsd/orm/cfg“:pr ...

  7. 依据错误原理解决Hibernate执行出现No CurrentSessionContext configured!错误

    (1)异常信息例如以下: 严重: Servlet.service() for servlet action threw exception java.lang.RuntimeException: &l ...

  8. 转 使用Hibernate操作数据库时报:No CurrentSessionContext configured! 异常

    没有currentSession配置错误,即在我们使用currentSession的时候要在hibernate.cfg.xml中进行相关的事务配置:1.本地事务<property name=&q ...

  9. Hibernate 异常提示_1

    INFO: HHH000041: Configured SessionFactory: null九月 15, 2016 12:29:35 上午 org.hibernate.engine.jdbc.co ...

随机推荐

  1. C++中定义比较函数的三种方法

    原文地址:http://fusharblog.com/3-ways-to-define-comparison-functions-in-cpp/ C++编程优与Pascal的原因之一是C++中存在ST ...

  2. Segment Tree 扫描线 分类: ACM TYPE 2014-08-29 13:08 89人阅读 评论(0) 收藏

    #include<iostream> #include<cstdio> #include<algorithm> #define Max 1005 using nam ...

  3. go lang学习笔记——channel机理及调度理解

    <Go语言编程>一书介绍了libtask库,可以认为这个库等同于go的底层goroutine实现. libtask库的channel的数据结构如下: struct Alt { Channe ...

  4. 编写一函数用来实现左右循环移位。函数原型为move(value,n);n>0时右移n位,n<0时左移|n|位。

    #include<stdio.h> #include<stdlib.h> int main(){ setbuf(stdout,NULL); int move(int,int); ...

  5. 解决vsftpd日志时间问题

    解决vsftpd日志时间问题 发布时间:August 29, 2008 分类:Linux <你必须承认土也是一种艺术> <Linux下查看Apache的请求数> 最近发现vsf ...

  6. delphi 网络函数

    Delphi网络函数 unit net; interfaceusessysutils,windows,dialogs,winsock,classes,comobj,wininet; //得到本机的局域 ...

  7. 【剑指offer】连续子数组最大和

    思路dp很清楚,就是要注意细节. int FindGreatestSumOfSubArray(vector<int> array) { ; ], tempsum = array[]; // ...

  8. iOS获取手机相关信息

    iOS具体的设备型号: #include <sys/types.h> #include <sys/sysctl.h> - (void)test { //手机型号. size_t ...

  9. 未能加载文件或程序集"Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad

    问题: 未能加载文件或程序集"Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3 ...

  10. Win32应用程序中文支持

    Settings--Editor---Encoding改为Windows 936 main.cpp中#include "locale.h" winmain中增加一行: setloc ...