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:
{{ { @Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class A { @Id @GeneratedValue private Long id; private String valA; // getters setters here }
}} {{@Entity public class SubA extends A { private String valSubA; // getters setters here }}}
JPQL query: {{select suba.valSubA from SubA suba}}
Translated SQL query: {{select suba0_.valSubA as col_0_0_ from SubA suba0_ inner join A suba0_1_ on suba0_.id=suba0_1_.id}}
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] |
|