Java 使用getCurrentSession在jboss上部署

Java 使用getCurrentSession在jboss上部署,java,hibernate,jboss,Java,Hibernate,Jboss,我已经在HibernateOffacory类中实现了基于的DAO,有一个方法 protected Session getCurrentSession() { return HibernateUtil.getSessionFactory().getCurrentSession(); } 为了实现相同的功能,我对hibernate.cfg.xml进行了如下文章所述的更改 我甚至设置了属性 <property name="hibernate.current_session_cont

我已经在HibernateOffacory类中实现了基于的DAO,有一个方法

protected Session getCurrentSession() {
     return HibernateUtil.getSessionFactory().getCurrentSession();
}
为了实现相同的功能,我对hibernate.cfg.xml进行了如下文章所述的更改

我甚至设置了属性

<property name="hibernate.current_session_context_class">jta</property>
我是不是错过了什么??
我的jboss版本是4.2.3,hibernate版本是3.3.1,使用Java 7。

对于基于线程的会话管理,我从hibernate.cfg.xml中删除了transaction.factory_类和manager_lookup_类属性,效果非常好。
但是对于基于jta的会话管理,我仍然会遇到同样的错误。

您知道如何管理事务吗?您有spring还是手动执行?公共静态会话getCurrentSession{Session currentSession=getSessionFactory.getCurrentSession;if!currentSession.getTransaction.isActive{currentSession.getTransaction.begin;}返回currentSession;}我不使用spring框架。如果我错了,请告诉我。Jboss应该通过这个属性自动处理事务。org.hibernate.transaction.jtatransactionfactory您似乎在Jboss内部运行,它有一个JTA事务管理器。你不应该这样开始交易。您应该使用EJB和声明性事务管理。只是为了指出确切的问题。每当我试图获取当前会话getSessionFactory.getCurrentSession时,我都会遇到问题。
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)