【问题标题】:Deploying on jboss using getCurrentSession使用 getCurrentSession 在 jboss 上部署
【发布时间】:2012-09-28 07:15:59
【问题描述】:

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

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。

【问题讨论】:

  • 您是如何管理交易的?你有弹簧还是手动做?
  • 公共静态会话 getCurrentSession() { 会话 currentSession = getSessionFactory().getCurrentSession(); if (!currentSession.getTransaction().isActive()) { currentSession.getTransaction().begin(); } 返回当前会话; }
  • 我不使用spring框架。如果我错了,请告诉我。Jboss 应该通过这个属性自动处理事务。org.hibernate.transaction.JTATransactionFactory
  • 你似乎在 JBoss 内部运行,它有一个 JTA 事务管理器。您不应该以这种方式自己开始交易。您应该使用 EJB 和声明式事务管理。
  • 只是为了查明确切的问题。每当我试图获取当前会话 getSessionFactory().getCurrentSession() 时,我都会遇到问题。

标签: java hibernate jboss


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多