没有Spring的Hibernate事务管理

时间:2012-04-26 07:26:08

标签: hibernate jdbc transactions

我想在没有Spring的情况下使用Hibernate,我以这种方式设置Hiberante:

<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>

但现在我得到了这个例外:

org.hibernate.HibernateException: get is not valid without active transaction

有什么方法可以像Spring一样让Hibernate自动管理事务呢?我必须手动打开和关闭交易吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

嗯,至少不是根据reference guide。您可以使用各种选项在托管和JTA环境中使用事务,但是您必须在Transaction位中编码