JPA (and inheritance), how do I get all the entities of a given superclass

Given the following entity definitions:

@Entity class abstract A { Collection<A> parents; } @Entity class B extends A { } @Entity class C extends A { } 

Is it possible to define a method that returns all entities of type B and C that have a given parent without , to make two separate calls and then merge the results?

 Collection<A> getAllByParentId(long id) 
+4
source share
1 answer

It should be so simple:

 List<A> results = entityManager .createQuery("Select a from A a", A.class) .getResultList(); 
+9
source

All Articles