Let me take a step back and weigh in more generally on this topic. JPA 2.0
(see section 4.6.17.4) allows queries to restrict the classes returned from
a polymorphic query. The expression looks like
SELECT e FROM Employee e WHERE TYPE(e) IN (FullTime, Executive)
and provides a useful technique for simple requests. This mechanism is not
present in JPA 1.0 and, even in 2.0, does not work for native queries.
For my situation, native queries are required to access SQL stored
procedures in the WHERE clause. I often require only the information in
the base classes but still desire full polymorphism elsewhere. The
JPA-standard solution would seem to be the following:
* Define a base class with @MappedSuperclass
@MappedSuperclass public abstract class XBase { ... }
* Define a non-inherited entity from the base class
@Entity public class XIndex extends XBase { ... }
* Define an inherited entity from the base class
@Inheritance(...) @DiscriminatorColumn(...) public class XChild extends
XBase { ... }
* Then create the children from the inherited entity
@Entity @DiscriminatorValue(...) public class Y extends XChild { ... }
If the query can instead be restricted via a fetch hint, the situation
simplifies considerably.
* Define a base class
@Entity @Inheritance(...) @DiscriminatorColumn(...) public class X { ...
}
* Create the children
@Entity @DiscriminatorValue(...) public class Y extends X { ... }
* Code:
javax.persistence.Query q = em.createNativeQuery(...);
q.setHint("openjpa.AllowedEntityTypes", "X"); // PROPOSED ONLY.
This eliminates the mapped superclass, eliminates the potential for a
mismatch between XIndex and XChild, and allows the entity type expressions
functionality to be extended to cover native queries.
--
View this message in context:
http://n2.nabble.com/How-to-disable-jpql-Polymorphic-Queries-tp3229800p4287813.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.