DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
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

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 (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(
at org.datanucleus.api.jpa.criteria.CriteriaQueryImpl.from(

Andy Jefferson added a comment - 26/Mar/13 10:46 AM
No testcase as per JIRA front page and all docs

Andy Jefferson made changes - 26/Mar/13 10:46 AM
Field Original Value New Value
Priority Major [ 3 ] Incomplete [ 6 ]
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

Patrice Blanchardie made changes - 26/Mar/13 01:36 PM
Attachment [ 11931 ]
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"

Andy Jefferson made changes - 27/Mar/13 10:21 AM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 3.2.1 [ 11911 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 27/Mar/13 10:21 AM
Priority Incomplete [ 6 ] Major [ 3 ]
Patrice Blanchardie added a comment - 27/Mar/13 11:36 AM
Thanks for the fast fix!

Patrice Blanchardie made changes - 27/Mar/13 11:40 AM
Comment [ If you tell me it's really a bug, I can prepare a Test Case. In other words, is this Criteria API implementation expected to support queries on an abstract Entity? (the code doesn't seem to).

If you tell me it's the expected behavior, I'll understand and a Test Case won't be necessary. ]
Andy Jefferson made changes - 06/Apr/13 05:29 PM
Status Resolved [ 5 ] Closed [ 6 ]