When you have an inheritance hierarchy with "joined" inheritance type and query something from a subclass, superclass is always joined in the query even though it is not needed. Example:
{code:java} @Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class A { @Id @GeneratedValue private Long id; private String valA; // getters setters here } {code}
{code:java} @Entity public class SubA extends A { private String valSubA; // getters setters here } {code}
JPQL query: {code :hql } select suba.valSubA from SubA suba {code}
Translated SQL query:
{code:sql} select suba0_.valSubA as col_0_0_ from SubA suba0_ inner join A suba0_1_ on suba0_.id=suba0_1_.id {code}
Super class table join is useless in the SQL query. It could be optimized.
I discussed that on [Hibernate forum|https://discourse.hibernate.org/t/how-to-omit-joining-of-superclass-in-jpa-when-im-querying-subclass-only/1310] |
|