Unnecessary inner joins with super-classes in a JOINED inheritance hierarchy generated for a SUBSELECT fetch query in Hibernate

Solution Verified - Updated -

Issue

  • An association is defined between entities X and C where C is a leaf-class in a JOINED inheritance hierarchy (C extends B which extends A).
  • In the SQL below generated for a SUBSELECT fetch query, the inner join clauses (on B and A) are not needed to filter the result set since the association is defined at the leaf (between X and C) and no properties/columns of B nor A are referenced in the query.

    select
        x.property1, ...
    from
        X x
    where
        x.fk in (
            select c.id 
            from C c 
            inner join B b on c.id=b.id
            inner join A a on c.id=a.id 
            where c.something=?
        )
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content