java - 使用 getCurrentSession 在 jboss 上部署

标签 java hibernate jboss

我已经基于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_classmanager_lookup_class 属性,它的工作就像一个魅力。
但是对于基于jta的 session 管理,我仍然遇到同样的错误。

关于java - 使用 getCurrentSession 在 jboss 上部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12635327/

相关文章:

java - HTTPURLConnection Getoutputstream 挂起

java - Java检查内存地址中==运算符的作用

java - jpa/hibernate 查询返回的实体中包含的过滤器列表

java - 使用 Hibernate 保存对象

java - FileInputStream 使用包路径

java ProcessBuilder 不起作用

java - 为什么我的实体管理器返回空结果列表?

java - 三层应用

java - 在 JBoss 社区 AS 7 中部署简单的 Jax-RS 示例

java - jetty worker jboss7 war 提交。服务器启动以不可恢复的方式失败