| Summary: | JPA2: Metamodel entity processing requires specified entities in persistence.xml to avoid IllegalArgumentException - The type [null] is not the expected [EntityType] for the key class | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Michael OBrien <michael.f.obrien> |
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | major | ||
| Priority: | P2 | CC: | eclipselink.orm-inbox, michael.f.obrien |
| Version: | unspecified | Flags: | michael.f.obrien:
documentation+
|
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| URL: | http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_101:_20100218:_Descriptor.javaClass_is_null_on_a_container_EM_for_a_specific_case | ||
| Whiteboard: | |||
| Bug Depends on: | 266912, 302606, 303722, 315287 | ||
| Bug Blocks: | 337034, 338709 | ||
| Attachments: | |||
|
Description
Michael OBrien
Created attachment 190293 [details]
Reproducing Java SE client jar
>This bug helps narrow down the cause of design issue 101 http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_101:_20100218:_Descriptor.javaClass_is_null_on_a_container_EM_for_a_specific_case >see related http://www.netbeans.com/projects/javaee/lists/issues/archive/2010-02/message/627 http://netbeans.org/bugzilla/show_bug.cgi?id=181068 http://stackoverflow.com/questions/3559691/jsf-crud-application-and-entities/5185057#5185057 http://netbeans.org/bugzilla/show_bug.cgi?id=180810 http://old.nabble.com/Re%3A-problem-with-criteria-The-type--null--is-not-the-expected--EntityType--for-the-key-class--class-br.com.thinkit.db.Ativos----try-upgrade-past-8141.-p30219742.html http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg05508.html http://forums.devshed.com/java-help-9/jpa-controller-not-work-in-ejb-706551.html not http://forum.springsource.org/archive/index.php/t-32323.html http://comments.gmane.org/gmane.comp.java.tynamo.user/173 http://forums.netbeans.org/post-90076.html http://netbeans.org/bugzilla/show_bug.cgi?id=191936 >Also update http://forums.oracle.com/forums/thread.jspa?threadID=1568571&tstart=225 http://netbeans-org.1045718.n5.nabble.com/JSF-CRUD-breakes-in-an-enterprise-application-td2971579.html http://www.computerbase.de/forum/showthread.php?t=800988 http://efreedom.com/Question/1-3559691/JSF-CRUD-Application-Entities EmbeddableType http://permalink.gmane.org/gmane.comp.java.tynamo.user/177 http://comments.gmane.org/gmane.comp.java.tynamo.user/173 ManagedType http://www.eclipse.org/forums/index.php?t=msg&goto=516480&#msg_516480 https://bugs.eclipse.org/bugs/show_bug.cgi?id=303722 https://bugs.eclipse.org/bugs/show_bug.cgi?id=302606 https://bugs.eclipse.org/bugs/show_bug.cgi?id=315287 >Point 3: a get from an empty Map should behave differently than a get where at least 1 key:value pair exist.
- we need to pick up on an empty map for ManagedType|EntityType}EmbeddableType and preemptively warn the user that the map is likely empty because the model classes were not found (in the case of a managed persistence unit at least)
- we need to differentiate between managed/unmanaged in our working
- we need to answer the question - is a persistence context without any entities/mappedSuperclasses or embeddables valid? Or can a persistence unit exist where no classes are marked with JPA annotations? I think in the case of the metamodel - no.
Therefore - an empty metamodel should not pass through predeploy as valid.
>An example output during an SE persistence context where the entities are not listed (in error)
[EL Finest]: 2011-03-07 17:21:17.884--ServerSession(18450577)--Thread(Thread[main,5,main])--End deploying Persistence Unit dao.create.tables.derby.client; session file:/C:/view_w36a/examples/org.eclipse.persistence.example.jpa.server.common.ddlgen/bin/_dao.create.tables.derby.client; state Deployed; factoryCount 1
[EL Warning]: 2011-03-07 17:21:17.899--Thread(Thread[main,5,main])--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork] will return null.
Exception in thread "main" java.lang.IllegalArgumentException: No [EntityType] was found for the key class [class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>class org.eclipse.persistence.example.distributed.collatz.model.UnitOfWork</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:170)
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:189)
at org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient.checkMetamodel(DDLGenerationClient.java:432)
at org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient.doQuery(DDLGenerationClient.java:457)
at org.eclipse.persistence.example.jpa.server.common.DDLGenerationClient.main(DDLGenerationClient.java:442)
Created attachment 190603 [details]
Metamodel change to warn about unreferenced model classes for Java SE and some Java EE container managed persistence contexts
>regression test results - with
<testsuite errors="0" failures="0" hostname="????-pc2" name="org.eclipse.persistence.testing.tests.jpa.AllCMP3TestRunModel" tests="2257" time="658.269" timestamp="2011-03-07T21:59:16">
Created attachment 190685 [details]
Full Metamodel change to warn about unreferenced model classes for Java SE and some Java EE container managed persistence contexts
>Test results >Invalid use case - parameter is null EmbeddableType cell_ = getEntityManager().getMetamodel().embeddable(null); [EL Warning]: 2011-03-08 15:18:47.35--Thread(Thread[main,5,main])--The collection of metamodel [EmbeddableType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [null] will return null. Exception in thread "main" java.lang.IllegalArgumentException: No [Embeddable] was found for the null key class parameter in the Metamodel - please specify the correct key class for the metamodel [Embeddable] class and verify that the key class was referenced in persistence.xml using a specific <class/> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. >Invalid use case - parameter is not an Entity EmbeddableType cell_ = getEntityManager().getMetamodel().embeddable(Object.class); [EL Warning]: 2011-03-08 15:19:36.764--Thread(Thread[main,5,main])--The collection of metamodel [EmbeddableType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class java.lang.Object] will return null. Exception in thread "main" java.lang.IllegalArgumentException: No [EmbeddableType] was found for the key class [java.lang.Object] in the Metamodel - please verify that the [Embeddable] class was referenced in persistence.xml using a specific <class>java.lang.Object</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. >Valid use case - but entities are not specified in persistence.xml EntityType cell_ = getEntityManager().getMetamodel().entity(Cell.class); [EL Warning]: 2011-03-08 15:20:37.331--Thread(Thread[main,5,main])--The collection of metamodel [EntityType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class org.eclipse.persistence.example.jpa.server.business.Cell] will return null. Exception in thread "main" java.lang.IllegalArgumentException: No [EntityType] was found for the key class [org.eclipse.persistence.example.jpa.server.business.Cell] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. >Valid use case - but entities are not specified in persistence.xml ManagedType cell_ = getEntityManager().getMetamodel().managedType(Cell.class); [EL Warning]: 2011-03-08 15:20:57.375--Thread(Thread[main,5,main])--The collection of metamodel [ManagedType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class org.eclipse.persistence.example.jpa.server.business.Cell] will return null. Exception in thread "main" java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [org.eclipse.persistence.example.jpa.server.business.Cell] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. EntityType cell_ = getEntityManager().getMetamodel().entity(Cell.class);
with <!-- exclude-unlisted-classes>false</exclude-unlisted-classes-->
[EL Warning]: 2011-03-08 16:18:37.339--Thread(Thread[main,5,main])--The collection of metamodel [EntityType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class org.eclipse.persistence.example.jpa.server.business.Cell] will return null.
Exception in thread "main" java.lang.IllegalArgumentException: No [EntityType] was found for the key class [org.eclipse.persistence.example.jpa.server.business.Cell] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
with <exclude-unlisted-classes>false</exclude-unlisted-classes>
cell_ EntityType: EntityTypeImpl@3190337:Cell [ javaType: class org.eclipse.persistence.example.jpa.server.business.Cell descriptor: RelationalDescriptor(org.eclipse.persistence.example.jpa.server.business.Cell --> [DatabaseTable(EL_CELL)]), mappings: 7]
EmbeddableType cell_ = getEntityManager().getMetamodel().embeddable(Object.class);
[EL Warning]: 2011-03-08 16:09:43.197--Thread(Thread[main,5,main])--The collection of metamodel [EmbeddableType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class java.lang.Object] will return null.
Exception in thread "main" java.lang.IllegalArgumentException: No [EmbeddableType] was found for the key class [java.lang.Object] in the Metamodel - please verify that the [Embeddable] class was referenced in persistence.xml using a specific <class>java.lang.Object</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
// when would you get a non-null type but with the wrong type
ManagedType cell_ = getEntityManager().getMetamodel().managedType(Cell.class);
with <!-- exclude-unlisted-classes>false</exclude-unlisted-classes-->
[EL Warning]: 2011-03-08 16:18:01.033--Thread(Thread[main,5,main])--The collection of metamodel [ManagedType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class org.eclipse.persistence.example.jpa.server.business.Cell] will return null.
Exception in thread "main" java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [org.eclipse.persistence.example.jpa.server.business.Cell] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
with <exclude-unlisted-classes>false</exclude-unlisted-classes>
cell_ EntityType: EntityTypeImpl@14779369:Cell [ javaType: class org.eclipse.persistence.example.jpa.server.business.Cell descriptor: RelationalDescriptor(org.eclipse.persistence.example.jpa.server.business.Cell --> [DatabaseTable(EL_CELL)]), mappings: 7]
EmbeddableType cell_ = getEntityManager().getMetamodel().embeddable(null);
[EL Warning]: 2011-03-08 16:07:44.311--Thread(Thread[main,5,main])--The collection of metamodel [EmbeddableType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [null] will return null.
Exception in thread "main" java.lang.IllegalArgumentException: No [EmbeddableType] was found for the null key class parameter in the Metamodel - please specify the correct key class for the metamodel [Embeddable] class and verify that the key class was referenced in persistence.xml using a specific <class/> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
// wrong type but existing
EmbeddableType cell_ = getEntityManager().getMetamodel().embeddable(Cell.class);
[EL Warning]: 2011-03-08 16:10:52.045--Thread(Thread[main,5,main])--The collection of metamodel [EmbeddableType] types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. The lookup on [class org.eclipse.persistence.example.jpa.server.business.Cell] will return null.
Exception in thread "main" java.lang.IllegalArgumentException: No [EmbeddableType] was found for the key class [org.eclipse.persistence.example.jpa.server.business.Cell] in the Metamodel - please verify that the [Embeddable] class was referenced in persistence.xml using a specific <class>org.eclipse.persistence.example.jpa.server.business.Cell</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
Created attachment 190696 [details]
Full Metamodel change to warn about unreferenced model classes for Java SE and some Java EE container managed persistence contexts
>SVN rev# 9102 https://fisheye2.atlassian.com/changelog/eclipselink?cs=9102 The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |