HibernateException: No Hibernate Session bound to thread
2014-12-14 15:09
429 查看
异常栈:
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:622)
at org.springside.modules.orm.hibernate.SimpleHibernateDao.getSession(SimpleHibernateDao.java:90)
at org.springside.modules.orm.hibernate.SimpleHibernateDao.createCriteria(SimpleHibernateDao.java:284)
at org.springside.modules.orm.hibernate.SimpleHibernateDao.findUniqueBy(SimpleHibernateDao.java:165)
使用SessionFactory.getCurrentSession执行hibernate操作时,hibernate的操作默认必须包含在一个transaction中,也就是开始要用session.begionTransaction得到一个transaction 实例(譬如tx), 操作结束时在这个实例上进行事务的提交tx.commit或回滚tx.rollback. 如果这些CRUD操作不被包括在一个具体的transaction中,hibernate就会抛出上述异常。
在实际的SSH web应用开发中,我们通常用spring来进行事务的管理。我们一般不会在dao层使用transaction,事务被配置在service层上更为合理,因为业务层方法表示逻辑上的一个原子操作。在这种环境下,如果你遇到上述异常,请考虑一下service层上没有配置transaction,transaction有没有打开!
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:622)
at org.springside.modules.orm.hibernate.SimpleHibernateDao.getSession(SimpleHibernateDao.java:90)
at org.springside.modules.orm.hibernate.SimpleHibernateDao.createCriteria(SimpleHibernateDao.java:284)
at org.springside.modules.orm.hibernate.SimpleHibernateDao.findUniqueBy(SimpleHibernateDao.java:165)
使用SessionFactory.getCurrentSession执行hibernate操作时,hibernate的操作默认必须包含在一个transaction中,也就是开始要用session.begionTransaction得到一个transaction 实例(譬如tx), 操作结束时在这个实例上进行事务的提交tx.commit或回滚tx.rollback. 如果这些CRUD操作不被包括在一个具体的transaction中,hibernate就会抛出上述异常。
在实际的SSH web应用开发中,我们通常用spring来进行事务的管理。我们一般不会在dao层使用transaction,事务被配置在service层上更为合理,因为业务层方法表示逻辑上的一个原子操作。在这种环境下,如果你遇到上述异常,请考虑一下service层上没有配置transaction,transaction有没有打开!
相关文章推荐
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transac
- No Hibernate Session bound to thread, and configuration does not allow creation of non-transactiona
- No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- 解决一个Sping管理hibernate时的事务问题(No Hibernate Session bound to thread)
- No Hibernate Session bound to thread, and configruation does not allow creation of non-transactional
- 继承类的@Transactional:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
- hibernate的session的No Hibernate Session bound to thread
- SmartGwt: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
- No Hibernate Session bound to thread, and configuration does not allow 解决办法
- 关于出现No Hibernate Session bound to thread问题的记录
- 关于出现No Hibernate Session bound to thread问题的记录
- spring hibernate No Hibernate Session bound to thread异常
- 报错:org.hibernate.HibernateException: No Hibernate Session bound to thread
- hibernate错误提示: No Hibernate Session bound to thread, and configuration does not allow creation of no
- No Hibernate Session bound to thread, and configuration does not allow
- No Hibernate Session bound to thread, and configuration does not allow creation of non-transactiona
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- 怪异的 No Hibernate Session bound to Thread !异常
- 继承类的@Transactional:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow crea