2

我正在尝试迁移 GlassFish 4.0 webapp 以部署在 WildFly 8.1.0 FINAL 上。该应用程序正确部署,但在发送 GET 请求后(例如键入 localhost:8080/meanful/),出现奇怪的错误:

2:57:15,493 ERROR [org.jboss.as.ejb3.invocation] (default task-4) JBAS014134: EJB Invocation failed on component SystemDaoImpl for method public abstract boolean com.meanful.service.system.SystemDao.contains(java.lang.String): javax.ejb.EJBException: java.lang.IllegalStateException: Unable to create EntityManager with SynchronizationType because PersistenceUnit is configured with resource-local transactions.

我的 persistence.xml 看起来像这样,并且在我的 GlassFish 4 服务器上使用相同版本的 EclipseLink 功能齐全。

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence     http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="mysqlPersistenceUnit" transaction-type="JTA">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <jta-data-source>java:/jdbc/mySQL</jta-data-source>
     <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
        </properties>
  </persistence-unit>
</persistence>

实现类本身如下所示:

@Stateless
public class SystemDaoImpl implements SystemDao {

@PersistenceContext private EntityManager entityManager;

@Override
public boolean contains(String infoKey) {
    return entityManager.find(SystemInfo.class, infoKey) != null;

    }

实体管理器被注入。当程序到达 contains() 方法的内部(只有一行)时,将引发错误。

连接设置正确,连接测试显示一切正常。 JTA 已启用 在此处输入图像描述

4

2 回答 2

2

请检查线路:

<resource-root path="jipijapa-eclipselink-1.0.1.Final.jar"/>

在您的modules/system/layers/base/org/eclipse/persistence/main/module.xml <resource>元素中。

jipijapa-eclipselink-1.0.1.Final.jar:

该库是实用程序类的集合,可帮助将 EclipseLink 集成到 JBossAS7

根据以下内容,应该有两行(集成和 eclipselink 库):

JPA 参考指南 - 使用 EclipseLink

于 2014-07-01T06:50:11.003 回答
1

此问题与 EclipseLink 相关。EclipseLink 2.5.1。在 persistence.xml 中定义为提供者。删除此声明并让捆绑在 WildFly 中的 Hibenate 完成工作后,一切正常。

我还没有弄清楚为什么会出现这个奇怪的错误。看起来 EclipseLink 认为事务管理是 RESOURCE_LOCAL。

于 2014-06-27T17:27:10.593 回答