Given the following entities:
{code} @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; } {code}
A For the query like :
{code} String queryHQL = "from InvestmentCompany investmentCompany " + "where exists " + "(select employee " + "from investmentCompany.employees as employee " + " where lower(employee.firstName) like :param1 )"; {code}
Results NOTE: employee.firstName is in Person table (not Employee)
The following SQL is generated :
{code} 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 ? ) ) {code}
The alias , {{employees1_1_}} does not correspond to any table involved in the query. Person table should be have been joined with Employee because {{ employees1_ firstName }} is declared in {{Person}} . |
|