我已经基于Link实现了DAO。在HibernateDAOFactory类中,有一个方法
protected Session getCurrentSession() {
return HibernateUtil.getSessionFactory().getCurrentSession();
}
为了实现相同的效果,我对 hibernate.cfg.xml 进行了更改,如以下文章 Here 1 中所述。 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。
最佳答案
对于基于线程的 session 管理,我从 hibernate.cfg.xml 中删除了 transaction.factory_class
和 manager_lookup_class
属性,它的工作就像一个魅力。
但是对于基于jta的 session 管理,我仍然遇到同样的错误。
关于java - 使用 getCurrentSession 在 jboss 上部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12635327/