No Hibernate Session bound to thread、No Session found f
来源:互联网 发布:陈都灵演技知乎 编辑:程序博客网 时间:2024/05/22 06:33
No Hibernate Session bound to thread、No Session found f
用springside3生成的项目
在App启动时,系统初始化加载的时候发生下面的错误
Java代码
- org.hibernate.HibernateException:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here -
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) -
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:700)
把其中的getCurrentSession改成openSession就可以使用,当没有事物启动的时候getCurrentSession是无法创建Session的。
参考:http://www.iteye.com/topic/87035
opensession是从sessionfactory得到一个新的session,所以可以使用,而getCurrentSession是从当前线程中得到事务开始时创建transaction的那个session,而你的事务没有能正确的启动,所以并没有一个session绑定到当前线程,所以你也得不到。
我的最终的解决办法是通过注解给我的service加上事务即可:@Transactional
补充:我在public class LoginController
直接使用DAO,而事物是加在service层,所以在controller层无法直接得到session,所以报错
解决方案:
@Transactional
public class LoginController {
0 0
- No Hibernate Session bound to thread、No Session found f
- No Hibernate Session bound to thread
- No Hibernate Session bound to thread
- HibernateException: No Hibernate Session bound to thread
- springmvc No Hibernate Session bound to thread
- HibernateException: No Hibernate Session bound to thread
- hibernate的session的No Hibernate Session bound to thread
- spring hibernate No Hibernate Session bound to thread异常
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and
- org.hibernate.HibernateException: No Hibernate Session bound to thread
- org.hibernate.HibernateException: No Hibernate Session bound to thread
- org.hibernate.HibernateException: No Hibernate Session bound to thread
- No Hibernate Session bound to thread纠结了很久
- 异常:No Hibernate Session bound to thread……
- No Hibernate Session bound to thread, and configuration
- No Hibernate Session boundNo Hibernate Session bound to thread, and configuration does not allow cr
- 解决一个Sping管理hibernate时的事务问题(No Hibernate Session bound to thread)
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- win2003下php开发有关环境搭建问题
- C#实现网页内容正文抓取
- arquillian + HSQLDB 单元测试问题整理
- hdu 最大报销额
- android调用.net的webservice的例子获取手机的归属地
- No Hibernate Session bound to thread、No Session found f
- IOS UISlider
- const
- Roman to Integer
- Ubuntu下AllJoyn源码编译方法
- 在vi中如何删除一行,复制多行,查找字符?
- Linux设备驱动程序学习(5)-高级字符驱动程序操作[(2)阻塞型I/O和休眠]
- STM32之CAN--CAN ID过滤器分析
- Generic detail view DetailView must be called with either an object pk or a slug.