struts2.3.16+spring4.0.6+hibernate4.3.5整合出现的No Session found for current thread
2014-07-16 14:04
393 查看
在使用struts2+spring4+hibernate4出现了No Session found for current thread具体如下:
在网上查找有人说配上这个<propkey="hibernate.current_session_context_class">thread</prop>就可以解决,配上后再次测试出现org.hibernate.HibernateException:No
CurrentSessionContext configured!或save is not valid without active transacton异常
处理这个问题处理好久没解决,我原来的做法是service直接继承BaseDao和BaseDaoImpl,其中BaseDao和BaseDaoImpl在com.base包下,service在com.service包下
<!--
配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
后来因为这个错误,尝试抽取BaseService和BaseServiceImpl并放在了com.base包下,结果同样报以上错误,后来突发奇想把BaseService和BaseServiceImpl移到了com.service,问题解决,测试通过
发现问题:配置的事务横切于在com.service包下所有类,而真正执行增删改查等数据库访问的方法是在com.Base包下。猜想:虽然service继承了BaseDao但是因为BaseDao不放在service包下,所以还是无法使用声明式事务管理...求高手帮验证...
提供参考:http://blog.csdn.net/dearLHB/article/details/20213283
org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) at com.xyc.mt.base.DaoSupportImpl.getSession(DaoSupportImpl.java:40) at com.xyc.mt.base.DaoSupportImpl.save(DaoSupportImpl.java:44) at cn.itcast.oa.test.TestService.testSerivce(TestService.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) 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.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 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)
在网上查找有人说配上这个<propkey="hibernate.current_session_context_class">thread</prop>就可以解决,配上后再次测试出现org.hibernate.HibernateException:No
CurrentSessionContext configured!或save is not valid without active transacton异常
处理这个问题处理好久没解决,我原来的做法是service直接继承BaseDao和BaseDaoImpl,其中BaseDao和BaseDaoImpl在com.base包下,service在com.service包下
<!--
配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
后来因为这个错误,尝试抽取BaseService和BaseServiceImpl并放在了com.base包下,结果同样报以上错误,后来突发奇想把BaseService和BaseServiceImpl移到了com.service,问题解决,测试通过
发现问题:配置的事务横切于在com.service包下所有类,而真正执行增删改查等数据库访问的方法是在com.Base包下。猜想:虽然service继承了BaseDao但是因为BaseDao不放在service包下,所以还是无法使用声明式事务管理...求高手帮验证...
提供参考:http://blog.csdn.net/dearLHB/article/details/20213283
相关文章推荐
- Spring framework3.2整合hibernate4.1报错:No Session found for current thread
- Spring 3 和 Hibernate4 整合时遇到的 No Session found for current thread !
- Spring整合hibernate No Session found for current thread
- SpringMVC 整合 hibernate 报错:No Session found for current thread
- Spring framework3.2整合hibernate4.1报错:No Session found for current thread
- 关于Spring3.2+Hibernate4.1整合问题:No Session found for current thread
- spring+hibernate整合:报错org.hibernate.HibernateException: No Session found for current thread
- SSH整合开发之异常:No Session found for current thread
- Spring framework3.2整合hibernate4.1报错:No Session found for current thread
- 在hibernate4中出现org.hibernate.HibernateException: No Session found for current thread
- No Session found for current thread
- Hibernate4 No Session found for current thread原因
- Hibernate4 No Session found for current thread原因
- Spring3 + Hibernate4 配置 No Session found for current thread问题的解决
- Hibernate4 与 spring3 集成Hibernate4 No Session found for current thread
- 关于在Spring中Hibernate的No Session found for current thread问题
- Sping3.1和hibernate4.2集成—— No Session found for current thread
- No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread