Search code examples
javaormjpapolymorphismtoplink

JPA/toplink heterogeneous list of entities


Colleagues, Using JPA I need resolve following issue: at database level exits 3 entities (saying SuperEntity, DetailsAEntity and DetailsBEntity). SuperEntity contains common part of fields for DetailsAEntity and DetailsBEntity.

So the question: is it possible to resolve collection of mixed elements DetailsAEntity and DetailsBEntity from JPA? May be exits some extension in toplink to specify class for entity?


Solution

  • Assuming SuperEntity is mapped as the root of the inheritance tree then the result of queries for this type can return a heterogeneous collection of its concrete subclasses.