Wrong SQL generated for HQL subquery referencing a superclass property in joined inheritance schema in Hibernate

Solution Unverified - Updated

Environment

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

Issue

  • An entity (e.g. Employee) extends a superclass (Person) in an InheritanceType.JOINED hierarchy

  • A superclass property (e.g. Person.firstName) is referenced in an HQL subquery involving the subclass

    ... where exists (select employee from company.employees as employee where lower(employee.firstName) like :param1 ...
    
  • The generated SQL references a non-existent join (the subclass/superclass table join is missing but referenced)

    ... where exists (select employees1_.id from Employee employees1_ where ... lower(employees1_1_.firstName) ...
    

Root Cause

This is a known Content from hibernate.atlassian.net is not included.defect in Hibernate.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.