Jakarta ee WildFly部署:无法使用SynchronizationType创建EntityManager
我正在尝试将GlassFish 4.0 webapp迁移到WildFly 8.1.0 FINAL上部署。应用程序部署正确,但在sendind GET请求(例如键入localhost:8080/meanful/)后,会出现奇怪的错误:Jakarta ee WildFly部署:无法使用SynchronizationType创建EntityManager,jakarta-ee,jpa,wildfly-8,Jakarta Ee,Jpa,Wildfly 8,我正在尝试将GlassFish 4.0 webapp迁移到WildFly 8.1.0 FINAL上部署。应用程序部署正确,但在sendind 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 me
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>
实体管理器被注入。当程序到达contains()方法的内部(只有一行)时抛出错误
连接设置正确,连接测试表明一切正常。
这个问题与日食有关。日食2.5.1。已在persistence.xml中定义为提供程序。删除此声明并让绑定在WildFly中的Hibenate完成其工作后,一切都正常
我还没有发现为什么会发生这种奇怪的错误。看起来EclipseLink认为事务管理是本地资源。请检查行:
在您的modules/system/layers/base/org/eclipse/persistence/main/module.xml
元素中
jipijapa-eclipselink-1.0.1.Final.jar:
此库是一组用于帮助集成的实用程序类
日食进入JBossAS7
应该有两行(集成和eclipselink库),如下所示:
猜猜看,您使用的是本地tx数据源吗?如果是,可能需要使用XA数据源:
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
我添加了一个带有数据源设置的屏幕截图。我觉得一切都很好。是的,我也觉得一切都很好。我尝试过只使用com.mysql.jdbc2.optional.MysqlDataSource创建非xa数据源,但没有效果。然而,在这两种情况下,ping(测试连接)都可以工作,它可能与数据源无关。另一个猜测是:你在写你正在使用EclipseLink,而WildFly使用Hibernate。是否您的部署中有一个EclipseLink jar,您可能只需要删除它?。。。那你为什么接受另一个答案呢?是哪一个?
@Stateless
public class SystemDaoImpl implements SystemDao {
@PersistenceContext private EntityManager entityManager;
@Override
public boolean contains(String infoKey) {
return entityManager.find(SystemInfo.class, infoKey) != null;
}