Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiN2M4ZjcwZmU1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16522?atlOrigin=eyJpIjoiN2M4Zj...
) HHH-16522 (
https://hibernate.atlassian.net/browse/HHH-16522?atlOrigin=eyJpIjoiN2M4Zj...
) HQL query produces SQL with incorrect ordering of joins (
https://hibernate.atlassian.net/browse/HHH-16522?atlOrigin=eyJpIjoiN2M4Zj...
)
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Components: query-hql
Created: 26/Apr/2023 04:56 AM Priority: Major Reporter: Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
See
https://stackoverflow.com/questions/76103479/hibernate-jpa-creates-an-inv....
Hibernate produces this SQL:
select
distinct t1_0.id,
t1_0.task_location_id
from
vin_task t1_0
join
vin_task_event_log t2_0
on t2_0.task_id=t1_0.id
join
vin_vineyard v1_0
on t4_0.vineyard_id=v1_0.id
join
vin_location t4_0
on t4_0.id=t1_0.task_location_id
given the following code:
@SessionFactory
@DomainModel(annotatedClasses = {BuggTest.Task.class, BuggTest.Location.class,
BuggTest.TaskLocation. class, BuggTest.Vineyard.class, BuggTest.TaskEventLog.class})
public class BuggTest {
@Test void test(SessionFactoryScope scope) {
scope.inTransaction( s-> {
s.createQuery(
"select distinct t from Task t join TaskEventLog tel on tel.task.id = t.id join
Vineyard v on t.taskLocation.vineyard.id = v.id" ,
Task.class).getResultList();
});
}
@Entity(name = "Task" )
@Table(name = "vin_task" )
public class Task {
@Id @GeneratedValue Long id;
@OneToOne(cascade = CascadeType.PERSIST, orphanRemoval = true )
@JoinColumn(name = "task_location_id" , referencedColumnName = "id"
)
private TaskLocation taskLocation;
}
@Entity(name = "TaskLocation" )
@Table(name = "vin_task_location" )
public class TaskLocation extends Location {
@Id @GeneratedValue Long id;
@OneToOne(mappedBy = "taskLocation" )
private Task task;
}
@Entity(name = "Location" )
@Table(name = "vin_location" )
public class Location {
@Id @GeneratedValue Long id;
@ManyToOne
@JoinColumn(name = "vineyard_id" )
private Vineyard vineyard;
}
@Entity(name = "Vineyard" )
@Table(name = "vin_vineyard" )
public class Vineyard {
@Id @GeneratedValue Long id;
}
@Entity(name = "TaskEventLog" )
@Table(name = "vin_task_event_log" )
public class TaskEventLog {
@Id @GeneratedValue
@JoinColumn(name = "task_id" )
Long id;
@ManyToOne Task task;
}
}
(
https://hibernate.atlassian.net/browse/HHH-16522#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16522#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100223- sha1:038ca59 )