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.
本文介绍如何正确配置Hibernate的getCurrentSession()方法,并确保在进行数据库查询时启动了事务。主要内容包括设置Hibernate属性和在代码中开始及提交事务。
1435

被折叠的 条评论
为什么被折叠?



