ITeye博客

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

hellostory · 2011-02-12 14:38 · Markdown

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.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。