我的应用程序具有一个复合持久性单元 mainPU ,其中包含2个成员( queryPU 和 entityPU )。在EclipseLink 2.5中使用Criteria API时,它没有任何问题。但是,升级到EclipseLink 2.7时,出现错误“在元模型中找不到键类[ XXX ]的[EntityType]”,其中 XXX 是在 entityPU
我对该问题有一些看法:
默认情况下,我的应用程序加载 mainPU 。如果我尝试获取元模型,它将始终返回空列表。如果我明确加载 在DAO中使用 entityPU 的EntityManagerFactory,则它可以加载EntityType的完整列表,问题就消失了!
EntityManagerFactory factory = Persistence.createEntityManagerFactory("entityPU");
Metamodel m2 = factory.getMetamodel(); //m2 return a list of EntityType!
我的EclipseLink 2.7应用程序中是否有错误的配置?
下面显示persistence.xml
mainPU
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="mainPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/appds</jta-data-source>
<jar-file>icms-entity-lib-0.2.9.544.jar</jar-file>
<jar-file>../icmshrnmc-ejb.jar</jar-file>
<properties>
<property name="jboss.entity.manager.jndi.name" value="java:jboss/persistence/mainPU" />
<property name="eclipselink.target-database"
value="org.eclipse.persistence.platform.database.oracle.Oracle11Platform" />
<property name="eclipselink.target-server" value="JBoss" />
<property name="eclipselink.composite-unit" value="true" />
<property name="eclipselink.session.customizer"
value="x.y.ejb.dao.entity.DefaultEntityInterceptor" />
<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.deploy-on-startup" value="true"/>
</properties>
</persistence-unit>
queryPU
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="queryPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/appds</jta-data-source>
<mapping-file>x/y/icmshrnmc/model/common/dao/namedquery/HrnNat.orm.xml</mapping-file>
...
...
...
<properties>
<property name="eclipselink.composite-unit-member" value="true" />
</properties>
</persistence-unit>
entityPU
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="entityPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/appds</jta-data-source>
<non-jta-data-source>java:jboss/datasources/appds</non-jta-data-source>
<mapping-file>x/y/fmk/model/application/dao/entity/AuditEntity.orm.xml</mapping-file>
...
...
...
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="eclipselink.jdbc.sequence-connection-pool" value="true" />
<property name="eclipselink.jdbc.sequence-connection-pool.non-jta-data-source" value="java:jboss/datasources/fmkseqds" />
</properties>