Omit joining of superclass table when querying subclass only

Description

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

Activity

Show:

Jan-Willem Gmelig Meyling October 17, 2019 at 9:33 AM

This issue seems causes regression HHH-13670

Jan-Willem Gmelig Meyling October 6, 2018 at 12:24 AM

Possibly a fix for this also allows omitting joins to secondary tables or join tables, as reported in HHH-12895.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Priority

Created September 27, 2018 at 7:54 AM
Updated July 24, 2020 at 7:00 AM
Resolved October 17, 2019 at 9:40 AM