Tomáš Müller (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b50823...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMWZkYmE5ZmUy...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16513?atlOrigin=eyJpIjoiMWZkYm...
) HHH-16513 (
https://hibernate.atlassian.net/browse/HHH-16513?atlOrigin=eyJpIjoiMWZkYm...
) Wrong query generated for a parent-child relation within the same table (
https://hibernate.atlassian.net/browse/HHH-16513?atlOrigin=eyJpIjoiMWZkYm...
)
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Attachments:
ORMStandaloneTestCase.java, SchedulingSubpart.java Components: hibernate-core Created:
25/Apr/2023 06:48 AM Environment: Java 11+ with Hibernate-core 6.2.1 Priority: Major
Reporter: 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 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 (
https://hibernate.atlassian.net/secure/attachment/50322/50322_SchedulingS... )
ORMStandaloneTestCase.java (
https://hibernate.atlassian.net/secure/attachment/50323/50323_ORMStandalo... )
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 )