在使用 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# TcpListener的编程要点

    using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...

  2. [原] blade中C++ singleton的实现

    最近看了龚大大KalyGE中的singleton, 觉得非常不错(C++中线程安全并且高效的singleton). 可惜blade的代码都是C++03的, 没有使用C++11的任何特性. 笔者对于si ...

  3. 功率单位mW 和 dBm 的换算

    无线电发射机输出的射频信号,通过馈线(电缆)输送到天线,由天线以电磁波形式辐射出去.电磁波到达接收地点后,由天线接收下来(仅仅接收很小很小一部分功率),并通过馈线送到无线电接收机.因此在无线网络的工程 ...

  4. HDOJ 1398 Square Coins 母函数

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  5. 移动MM failed to find resource file{mmiap.xml}

    原地址:http://blog.csdn.net/alking_sun/article/details/36175861 在进行移动MM集成的时候总是会遇到一个bug:  failed to find ...

  6. photoshop基础

    在Photoshop中,对图像的某个部分进行色彩调整,就必须有一个指定的过程.这个指定的过程称为选取.选取后形成选区. 现在先明确两个概念: 选区是封闭的区域,可以是任何形状,但一定是封闭的.不存在开 ...

  7. cf div2 238 D

    D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  8. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  9. CSS深入理解之line-height

    以下文字整理自慕课网——张鑫旭的<CSS深入理解之line-height>. line-height,又称行高,指的是两行文字基线之间的距离,又可以称为这行文字所占的高度. 定义三问: 什 ...

  10. asp.net跳转页面的三种方法比较

    目前,对于学习asp.net的很多朋友来讲,实现跳转页面的方法还不是很了解.本文将为朋友们介绍利用asp.net跳转页面的三种方法,并对其之间的形式进行比较,希望能够对朋友们有所帮助. ASP.NET ...