I am using EclipseLink as a JPA provider. Next, I use the following inheritance structure TABLE_PER_CLASS
@javax.persistence.Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @NamedQueries({ @NamedQuery(name=Parent.QUERY_FIND_ALL, query="SELECT p FROM Parent p") }) public class Parent {
Now the problem is that I want to get only the records of the parent class. But with the named query "SELECT p FROM Parent p", all records from the child table are also returned.
The selection or search code is as follows:
public List findWithNamedQuery(String query) { return em.createNamedQuery(query).getResultList(); }
Thus, the query is, for example, "SELECT p FROM Parent p".
How can I get only parent records and not all records of this inheritacne hierarchy?
In short: how can I leave all child records intact and return only parent records?
EDIT 1:
I use EclipseLink 2.0.1, but every time I try to use the axtavt solution with a type expression, I get the following error:
"Invalid Type Expression on [my.domain.Parent]. The class does not have a descriptor, or a descriptor that does not use inheritance or uses a ClassExctractor for inheritance".
I upgraded to the latest stable version 2.1.1 of EclipseLink, but this does not solve the problem.
inheritance jpa table-per-class
gerry
source share