错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
来源:互联网 发布:源码apache建站 编辑:程序博客网 时间:2024/05/04 15:06
版本:Hibernate_Core 3.3.2
在使用3.2的时候获取Session习惯使用sf.openSession();
但是现在开始流行getCurrentSession();了,原因很简单,openSession()是不管任何情况都重新开启一个Session,而getCurrentSession();相对的增加了一个判断,在有Session的情况下就会直接去调用,没有session的话才会创建,相对而言,好处显而易见了吧!
我碰见的错误消息
看看错误消息:没有CurrentSessionContext的配置!
呵呵.网上搜索了一下,原来
在集成Hibernate的环境下(例如Jboss),要在hibernate.cfg.xml中session-factory段加入:
在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入:
现在再使用getCurrentSession()方法获取session.没有错误了。
在使用3.2的时候获取Session习惯使用sf.openSession();
但是现在开始流行getCurrentSession();了,原因很简单,openSession()是不管任何情况都重新开启一个Session,而getCurrentSession();相对的增加了一个判断,在有Session的情况下就会直接去调用,没有session的话才会创建,相对而言,好处显而易见了吧!
我碰见的错误消息
- org.hibernate.HibernateException: No CurrentSessionContext configured!
- at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:620)
- at com.hibernate.test.HibernateTest.testSave01(HibernateTest.java:23)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
- at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
- at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
- at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
- at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
- at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
- at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
- at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
- at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
- at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
- at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
- at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
- at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
看看错误消息:没有CurrentSessionContext的配置!
呵呵.网上搜索了一下,原来
在集成Hibernate的环境下(例如Jboss),要在hibernate.cfg.xml中session-factory段加入:
- <property name="current_session_context_class">jta</property>
在不集成Hibernate的环境下(例如使用JDBC的独立应用程序),在hibernate.cfg.xml中session-factory段加入:
- <property name="current_session_context_class">thread</property>
现在再使用getCurrentSession()方法获取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!
- 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!
- hibernate异常org.hibernate.HibernateException: No CurrentSessionContext configured!
- Hibernate3.6:org.hibernate.HibernateException: No CurrentSessionContext configured!
- 异常之org.hibernate.HibernateException: No CurrentSessionContext configured
- 分数的四则运算(c++重载练习)
- 使用github管理Eclipse分布式项目开发
- 4.2 CMMI4级——组织过程性能(Organizational Process Performance)
- itween 动画
- itween 插件
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- eclipse中如何导入workspace中的项目
- HibernateUtil范例
- static代码块深究
- [RBP]RaspberryPi系列之三:NEW seven-part OpenCV 2.4.6.1 and Pi Camera Board - Updated!
- Android下查询系统源码看短信的显示
- 优秀程序员的十个习惯
- DP 学习网站总结
- rootkit的检测工具使用(chkrootkit和rootkit hunter)