jakarta-ee - WildFly部署: Unable to create EntityManager with SynchronizationType

标签 jakarta-ee jpa wildfly-8

我正在尝试迁移 GlassFish 4.0 Web 应用程序以部署在 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;

    }

实体管理器已注入(inject)。当程序到达 contains() 方法内部(只有一行)时抛出错误。

连接设置正确,连接测试显示一切正常。 JTA is enabled enter image description here

最佳答案

请检查行:

<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:

This library is a collection of utility classes to aid the integration of EclipseLink into JBossAS7

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

JPA Reference Guide - Using EclipseLink

关于jakarta-ee - WildFly部署: Unable to create EntityManager with SynchronizationType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24450379/

相关文章:

java - RestEasy异步请求空指针异常

jakarta-ee - 如何将动态生成的 SVG 包含到 Vaadin UI?

java - 无法识别 @Size 注释 (JPA)

java - 如何从 WildFly 调试日志中删除 Hibernate 调试语句

Java 按字符串查找和比较成员(也许是 JPA 功能?)

java - 从 4.2.7/4.3.0.CR1 开始,Hibernate JPA OneToOne 孤立删除仍然不起作用

java - 将部署的 jar 引用为 Maven 依赖项

java - 在 Eclipse 中设置 EJB 构建类路径

java - 带分页的数据表中的 Wicket 复选框

java - Hibernate 无法访问 phpMyAdmin 插入的数据