使用getCurrentSession在jboss上部署

时间:2012-09-28 07:15:59

标签: java hibernate jboss

我在HibernateDAOFactory类中实现了基于Link的DAO,有一个方法

protected Session getCurrentSession() {
     return HibernateUtil.getSessionFactory().getCurrentSession();
}

为了实现相同的目标,我已根据以下文章Here 1中所述更改了hibernate.cfg.xml HERE 2

    <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property><br/>
    <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
    <property name="hibernate.current_session_context_class">thread</property>

在jboss上部署它时会出现以下错误

org.hibernate.TransactionException: could not register synchronization

我甚至设置了属性

<property name="hibernate.current_session_context_class">jta</property>

但是我收到了以下错误。

 Caused by: org.hibernate.HibernateException: Unable to locate current JTA transaction

 at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:88)

 at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)

我错过了什么吗? 我的jboss版本是4.2.3,hibernate版本是3.3.1并使用Java 7。

1 个答案:

答案 0 :(得分:0)

对于基于线程的会话管理,我从hibernate.cfg.xml中删除了transaction.factory_classmanager_lookup_class属性,它就像一个魅力。
但是对于基于jta的会话管理,我仍然会遇到同样的错误。