错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
来源:互联网 发布:淘宝dw去除热点边框 编辑:程序博客网 时间:2024/05/16 04:37
版本: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.没有错误了, 马上过年了,大家写码愉快!
0 0
- 错误: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
- 博客初笔
- lightOJ 1047 Neighbor House (DP)
- Think in Java(十一):类型信息
- 一道提交过很多次才过的水题= = 回文数字
- Python实例浅谈之六读写文件
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- zynq交叉编译环境搭建
- CoreData最新讲解
- myeclipse6.5序列号生成
- Python面试题汇总
- Window下利用命令行提交代码到GitHub
- 移动MM 支付SDK遇到的问题
- RPCZ中的智能指针单例
- 重置样式css(Eric Meyer的原版)