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 . We have an entity that may point (optionally) points to itself to provide a parent-child relation:
{noformat} @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; } } {noformat}
For the following HQL {{ select s.id, p.id from SchedulingSubpart s inner join s.parentSubpart p }}
generates the following SQL gets generated {noformat} select s1_0.id from subpart s1_0 join subpart p1_0 on p1_0.id=s1_0.parent {noformat}
And returning the This is not correct. The same id is returned for the subpart entity and its parent (p1_0.id is not returned).
See
[^SchedulingSubpart.java] [^ORMStandaloneTestCase.java]
for more details. |
|