现在的位置: 首页 > 综合 > 正文

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transac

2013年08月08日 ⁄ 综合 ⁄ 共 1190字 ⁄ 字号 评论关闭

first of all if you want to use getcurrentSession() method you need to add these properties to HibernateProperties:
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
 

添加后如下:

 


second thing is from the exception, Hibernate3 doesn't allow you to run queries without starting a transaction. you have to add this to your init method before running the query:
sessionFactory.getCurrentSession().beginTransactio n();
and of course commit it in the end of your unit of work.

抱歉!评论已关闭.