Tomáš Müller (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b50823...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmJlY2UzZjQw...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16513?atlOrigin=eyJpIjoiNmJlY2...
) HHH-16513 (
https://hibernate.atlassian.net/browse/HHH-16513?atlOrigin=eyJpIjoiNmJlY2...
) Wrong query generated for a parent-child relation within the same table (
https://hibernate.atlassian.net/browse/HHH-16513?atlOrigin=eyJpIjoiNmJlY2...
)
Change By: Tomáš Müller (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b50823...
)
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.
(
https://hibernate.atlassian.net/browse/HHH-16513#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16513#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:cdc0af3 )