当我将EclipseLink从2.5.2升级到2.7.4时,在使用Criteria API选择数据时遇到了异常。无论如何,如果我更改为JPQL,则异常消失了。但是,由于使用Criteria API的系统中有很多区域,因此无法将它们全部更改为JPQL。另外,使用EclipseLink 2.5.2时我也没有这样的问题。请帮忙!
12:09:17,383 ERROR [stderr] (default task-47) Caused by: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [hk.judiciary.icms.model.dao.entity.HrnRsltCd] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>hk.judiciary.icms.model.dao.entity.HrnRsltCd</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
12:09:17,404 ERROR [stderr] (default task-47) at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:180)
12:09:17,404 ERROR [stderr] (default task-47) at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:202)
12:09:17,404 ERROR [stderr] (default task-47) at org.eclipse.persistence.internal.jpa.querydef.CommonAbstractCriteriaImpl.internalFrom(CommonAbstractCriteriaImpl.java:119)
12:09:17,405 ERROR [stderr] (default task-47) at org.eclipse.persistence.internal.jpa.querydef.AbstractQueryImpl.from(AbstractQueryImpl.java:275)
在此附上Critieria API程序:
CriteriaBuilder builder = getEntityManager().getEntityManagerFactory()
.getCriteriaBuilder();
CriteriaQuery<HrnRsltCd> criteria = builder.createQuery(HrnRsltCd.class);
Root<HrnRsltCd> root = criteria.from(HrnRsltCd.class);
criteria = criteria.select(root);
List<Predicate> andPredicates = new ArrayList<Predicate>();
// Active Flag
andPredicates.add(builder.equal(root.get(PARAM_ACTIVE_FLAG), "1"));
if (!CommonUtil.isNullOrEmpty(andPredicates)) {
criteria.where(andPredicates.toArray(new Predicate[0]));
}
TypedQuery<HrnRsltCd> query = getEntityManager().createQuery(criteria);
return this.getResultList(query);
在这里附加persistence.xml
<?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="icmshrnmcPU" 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/icmshrnmcPU" />
<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="hk.judiciary.fmk.ejb.dao.entity.DefaultEntityInterceptor" />
<property name="eclipselink.deploy-on-startup" value="true"/>
</properties>
</persistence-unit>
</persistence>
2个jar文件(icms-entity-lib-0.2.9.544.jar和icmshrnmc-ejb.jar)也都有其persistence.xml,它们具有不同的持久性单元名称。