We're updating the issue view to help you get more done. 

HQL subquery with constraint property in superclass does not join superclass table

Description

Given the following entities:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 @Entity(name="Person") @Inheritance(strategy = InheritanceType.JOINED) public static abstract class Person { @Id @GeneratedValue @Column private Long id; @Basic(optional = false) @Column(nullable = false) private String firstName; } @Entity(name="Employee") public static class Employee extends Person { @Id @GeneratedValue @Column private Long id; private int employeeNumber; @ManyToOne(optional = false) @JoinColumn(nullable = false) private InvestmentCompany company; }

For the query:

1 2 3 4 5 String queryHQL = "from InvestmentCompany investmentCompany " + "where exists " + "(select employee " + "from investmentCompany.employees as employee " + " where lower(employee.firstName) like :param1 )";

NOTE: employee.firstName is in Person table (not Employee)

The following SQL is generated:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 SELECT investment0_.id AS id1_0_, investment0_1_.fullName AS fullName2_0_, investment0_1_.shortName AS shortNam3_0_, investment0_.investorType AS investor1_2_ FROM InvestmentCompany investment0_ INNER JOIN CompanyBase investment0_1_ ON investment0_.id=investment0_1_.id WHERE EXISTS ( SELECT employees1_.id FROM Employee employees1_ WHERE investment0_.id=employees1_.company_id AND ( LOWER(employees1_1_.firstName) LIKE ? ) )

The alias, employees1_1_ does not correspond to any table involved in the query. Person table should have been joined with Employee because firstName is declared in Person.

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.11
5.2.3
4.1.4
4.2.21

Priority

Major