没有Spring的Hibernate事务管理

没有Spring的Hibernate事务管理,hibernate,jdbc,transactions,Hibernate,Jdbc,Transactions,我想在没有Spring的情况下使用Hibernate,我通过以下方式设置Hibernate: <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property> <property name="hibernate.current_session_context_class">thread</property>

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

<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
有没有办法让Hibernate像Spring一样自动管理事务?我必须手动打开和关闭交易吗


谢谢你。

好吧,至少根据报纸上的报道是这样的。您可以在托管和JTA环境中使用各种事务选项,但是您必须在
事务
位中编码

如果每个http请求都有一个会话,我应该在Tomcat中有一个过滤器来打开一个关闭的会话?我希望有什么东西能自动做到这一点。。。谢谢,我想到了一个过滤器来打开和关闭。。。这对你来说是个好选择吗?是的,这是参考指南中推荐的方法之一。AOP是另一种方式。getCurrentSession()是Hibernate 3中的一个新添加项,它可以非常方便地在持久层获取当前事务的会话。
org.hibernate.HibernateException: get is not valid without active transaction