While migrating to the latest version of Hibernate, we have discovered an issue with how queries are generated for parent-child relations within the same table. Here is a simple example, we have an entity that may point to itself to provide a parent-child relation: @Entity @Table(name = "subpart") public class SchedulingSubpart { private Long id; private SchedulingSubpart parentSubpart; @Id @Column(name = "id") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @ManyToOne(optional = true) @JoinColumn(name = "parent") public SchedulingSubpart getParentSubpart() { return parentSubpart; } public void setParentSubpart(SchedulingSubpart parentSubpart) { this.parentSubpart = parentSubpart; } } For the following HQL select s.id, p.id from SchedulingSubpart s inner join s.parentSubpart p generates the following SQL select s1_0.id from subpart s1_0 join subpart p1_0 on p1_0.id=s1_0.parent And returning the same id for the subpart and its parent (p1_0.id is not returned). See SchedulingSubpart.java ORMStandaloneTestCase.java for more details. |