HQL with subquery with entity path at least two levels deep produces wrong SQL

Description

If we have for example these entities:

 

@Entity class A implements Serializable { private static final long serialVersionUID = -5412503864464287451L; @Id @GeneratedValue long id; @ManyToOne B b; } @Entity class B implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue long id; @ManyToOne C c; } @Entity class C implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue long id; }

HQL like this:

select a.id from A a where exists (select b.id from B b where a.b.c.id = 5) will produce SQL:

select a1_0.id from A a1_0 where exists(select b1_0.id from B b1_0,B b2_0 where b2_0.c_id=5)

This is obviously wrong as b2_0 should be in correlation with a1_0 . Exists is not a factor here as this does not work with in either. Attached test contains more examples, see console output.

Attachments

1
  • 30 May 2023, 03:48 PM

Activity

Show:
Fixed

Details

Assignee

Reporter

Worked in

Sprint

Fix versions

Affects versions

Priority

Created May 30, 2023 at 3:46 PM
Updated June 30, 2023 at 11:45 AM
Resolved June 20, 2023 at 4:40 PM