Issue Details (XML | Word | Printable)

Key: NUCJPA-228
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Patrice Blanchardie
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus API JPA

Criteria doesn't support querying abstract @Entity

Created: 26/Mar/13 10:42 AM   Updated: 06/Apr/13 05:29 PM   Resolved: 27/Mar/13 10:21 AM
Component/s: API
Affects Version/s: 3.2.0.release
Fix Version/s: 3.2.1

File Attachments: 1. Zip Archive TEST-NUCJPA-228.zip (9 kB)


Severity: Development


 Description  « Hide
DataNucleus claims it support querying `@MappedSuperclass`, but their Criteria API implementation doesn't seem to support querying simple abstract `@Entity`.

In version 3.2.0, the code for `<X> Root<X> from(Class<X> cls)` includes the following line (197):

    EntityType<X> entity = model.entity(cls);

In my understanding, it will only work with types registered as "EntityType"

The problem is that DataNucleus `MetamodelImpl` treats abstract entities as "MappedSuperclassType" instead of "EntityType", so I get the following exception when querying (with Spring Data JPA, btw):

    Caused by: java.lang.IllegalArgumentException: Type <type> is not a known entity type
at org.datanucleus.api.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:193)
at org.datanucleus.api.jpa.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:197)


Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 26/Mar/13 10:46 AM
No testcase as per JIRA front page and all docs

Patrice Blanchardie added a comment - 26/Mar/13 01:36 PM
here is a Test Case:

Tests in error:
  test(org.datanucleus.test.CustomRepositoryTest): Type org.datanucleus.test.SampleAbstractEntity is not a known entity type; nested exception is java.lang.IllegalArgumentException: Type org.datanucleus.test.SampleAbstractEntity is not a known entity type

Andy Jefferson added a comment - 27/Mar/13 10:21 AM
Previously didn't explicitly store whether a class was MappedSuperClass or Entity (since it is a pointless attribution to a persistence tool), and in MetaModel used isAbstract to decide which category to put the classes in. Now explicitly saves the JPA "categorisation" and so the MetaModel matches what was in user metadata, consequently anything marked as Entity will be queryable using the birth-defect known as "Criteria"

Patrice Blanchardie added a comment - 27/Mar/13 11:36 AM
Thanks for the fast fix!