0
点赞
收藏
分享

微信扫一扫

Bug库____org.hibernate.HibernateException: No Session found for current thread


@bug出现情况

1.spring整合hibernate时抽取出公共的dao和dao的实现确定没有配置错

Bug库____org.hibernate.HibernateException: No Session found for current thread_java

Hibernate升级到4.x以后,在Spring中,通过Hibernate访问数据库的方法已经发生了变化,

不再是以往让自己的DAO实现类继承HibernateDAOSupport,

然后使用getHibernateTemplate()方法,操作数据库。新的模式下,只能通过从Spring注入的SessionFactory,

使用Hibernate原生的方法,操作数据库。

org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(


at org.springframework.orm.hibernate4.SpringSessionContext.currentSession( SpringSessionContext.java:97 )

at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1041)

at com.frame.base.dao.BaseDaoImpl.getCurrentSession(

BaseDaoImpl.java:28 )

at com.frame.base.dao.BaseDaoImpl.save(BaseDaoImpl.java:35)

at com.frame.student.test.Test.insertStudent(Test.java:34)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)

at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)

at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)


at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

解决方案;

1.applicationcontext.xml配置如下

Bug库____org.hibernate.HibernateException: No Session found for current thread_java_02

Bug库____org.hibernate.HibernateException: No Session found for current thread_hibernate_03

详细配置请看_栏目_框架整合_spring整合hibernate实例

举报

相关推荐

0 条评论