在使用 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. cygwin and its host machine

    Senario 本来我是想要修改下 machine name 在Ubuntu中的步骤是这样的 1 sudo hostname newMechineName 2 sudo vi /etc/hostnam ...

  2. 图解Git/图形化的Git参考手册

    此页图解git中的最常用命令.如果你稍微理解git的工作原理,这篇文章能够让你理解的更透彻. 基本用法 上面的四条命令在工作目录.暂存目录(也叫做索引)和仓库之间复制文件. ● git add fil ...

  3. ExtJS登陆页面涉及到的几个问题

    1.如何在文本框中增加提示信息      输入框中无法直接使用tooltip,需要使用单独的代码 var tip = Ext.create('Ext.tip.ToolTip', { target : ...

  4. mac上安装port

    今天和大家分享下 在mac os x 上安装port 本人在  OS X El Capitan 版本的操作系统上进行安装并测试. --------------------------------- 第 ...

  5. eclipse安装androidSDK地址,Android SDK Manager简介

    eclipse安装android插件地址:https://dl-ssl.google.com/android/eclipse 这个和安装其他插件方式一样:Help—Install New Softwa ...

  6. hibernate缓存机制详细分析

    转自:http://www.cnblogs.com/xiaoluo501395377/p/3377604.html 在本篇随笔里将会分析一下hibernate的缓存机制,包括一级缓存(session级 ...

  7. highchart 导出图片, 显示空白

    使用highchart时, 导出的图片会变空白..   解决方案: 不要加载grid.js

  8. [开发]Win7环境下Eclipse连接Hadoop2.2.0

    准备: 确保hadoop2.2.0集群正常运行 1.eclipse中建立mven工程,并编辑pom文件如下 <dependencies> <dependency> <gr ...

  9. Pytho中两种方式导入模块的差别

    1.使用import module,只是把模块导入,访问模块中的函数名或者是属性是必须使用点运算符(.)来访问,否则直接访问会提示找不到这些函数或者属性. 2.使用from numpy import ...

  10. TKStudio 4.6IDE Warning: L6310W: Unable to find ARM libraries.

    我也遇到了同样的问题.搞了很久,按下面的操解决了 内容转至:http://bbs.zlgmcu.com/dv_rss.asp?s=xh&boardid=43&id=23032& ...