我正在尝试迁移 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() 方法内部(只有一行)时抛出错误。
连接设置正确,连接测试显示一切正常。
最佳答案
请检查行:
<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:
block 引用>This library is a collection of utility classes to aid the integration of EclipseLink into JBossAS7
应该有两行(集成和 eclipselink 库),根据:
关于jakarta-ee - WildFly部署: Unable to create EntityManager with SynchronizationType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24450379/