org.hibernate.HibernateException: No Hibernate Session bound to thread
2014-06-19 00:40
369 查看
项目启动时抛异常:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
出现此异常的情况或有多种:DataSource数据源、事务未正常运行、session获取失败。
先说说spring如何对事务和hibernate session进行管理的:
1.getCurrentSession()是必须提交事务的。故使用getSessionFactory().getCurrentSession()时,这个方法一定是要配置声明式事务管理。
2.openSession()恰恰是与以上的方法想法,它不需要提交事务。但是他的资源必须手动关闭。
相对以上两点,解决方法有
1.获得session时使用openSession()。
2.若用到getCurrenctSession(),需在sessionFactory中配置(当然也可以使用注解,在service类加上事务@Transactional)
出现此异常的情况或有多种:DataSource数据源、事务未正常运行、session获取失败。
先说说spring如何对事务和hibernate session进行管理的:
1.getCurrentSession()是必须提交事务的。故使用getSessionFactory().getCurrentSession()时,这个方法一定是要配置声明式事务管理。
2.openSession()恰恰是与以上的方法想法,它不需要提交事务。但是他的资源必须手动关闭。
相对以上两点,解决方法有
1.获得session时使用openSession()。
2.若用到getCurrenctSession(),需在sessionFactory中配置(当然也可以使用注解,在service类加上事务@Transactional)
<prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
相关文章推荐
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and
- ssh 中报错:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not
- 继承类的@Transactional:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow crea
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- 报错:org.hibernate.HibernateException: No Hibernate Session bound to thread
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- 继承类的@Transactional:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
- org.hibernate.HibernateException: No Hibernate Session bound to thread
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not a
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transac
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not
- No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration
- org.hibernate.HibernateException: No Hibernate Session bound to thread
- 关于出现No Hibernate Session bound to thread问题的记录
- No Hibernate Session bound to thread, and configuration does not allow creation of non-transactiona
- org.hibernate.HibernateException: No Session found for current thread