我正在尝试迁移 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() 方法的内部(只有一行)时,将引发错误。
连接设置正确,连接测试显示一切正常。