org.hibernate.HibernateException: No CurrentSessionContext configured!
2014-09-08 14:01
417 查看
今天,在做关于hibernate的练习,结果一切都是与题目无异,但却报出
有点不解,虽然我的英语不好,但也知道这个的意思是没有当前的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.没有错误了,。
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.没有错误了,。
相关文章推荐
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured! at org.hibernate.internal.Se
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!
- 小白日记_错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
- 错误:org.hibernate.HibernateException:No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- 打开session的方法和org.hibernate.HibernateException: No CurrentSessionContext configured! 异常
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- org.hibernate.HibernateException: No CurrentSessionContext configured
- 异常之org.hibernate.HibernateException: No CurrentSessionContext configured
- org.hibernate.HibernateException: No CurrentSessionContext configured!