@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;
}
}