您的位置:首页 > 其它

org.hibernate.HibernateException: No CurrentSessionContext configured!

2014-09-08 14:01 417 查看
今天,在做关于hibernate的练习,结果一切都是与题目无异,但却报出


org.hibernate.HibernateException: No CurrentSessionContext configured!

有点不解,虽然我的英语不好,但也知道这个的意思是没有当前的Session,但平时做的hiberante也是这样获得Session的,应该是没有错的,结果网上一查,原来这个只是个例。
解决的方法是配置sessionFactory中的参数

在集成Hibernate的环境下(例如Jboss),要在hibernate.cfg.xml中session-factory段加入:

Xml代码


<property name="current_session_context_class">jta</property>

在不集成Hibernate的环境下(例如使用JDBC的独立应用程序)(我的情况就是这个),在hibernate.cfg.xml中session-factory段加入:

Xml代码


<property name="current_session_context_class">thread</property>

现在再使用getCurrentSession()方法获取session.没有错误了,。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐