From 2c85e5d190141cb7fbb58d8bc49803a57644b442 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 14 Feb 2024 00:16:26 +0100 Subject: [PATCH] HHH-16522 add test for fixed bug --- .../query/hql/joinorder/JoinOrderTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/joinorder/JoinOrderTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/joinorder/JoinOrderTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/joinorder/JoinOrderTest.java new file mode 100644 index 0000000000..75ccb663ed --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/joinorder/JoinOrderTest.java @@ -0,0 +1,72 @@ +package org.hibernate.orm.test.query.hql.joinorder; + +import jakarta.persistence.*; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +@SessionFactory +@DomainModel(annotatedClasses = {JoinOrderTest.Task.class, JoinOrderTest.Location.class, JoinOrderTest.TaskLocation.class, JoinOrderTest.Vineyard.class, JoinOrderTest.TaskEventLog.class}) +@TestForIssue(jiraKey="HHH-16522") +public class JoinOrderTest { + + @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; + } + +} \ No newline at end of file