Staffan Hörke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMGQzZjFmNjFk...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16473?atlOrigin=eyJpIjoiMGQzZj...
) HHH-16473 (
https://hibernate.atlassian.net/browse/HHH-16473?atlOrigin=eyJpIjoiMGQzZj...
) Join fetch a recursive relationship with EmbeddedId fetches wrong values (
https://hibernate.atlassian.net/browse/HHH-16473?atlOrigin=eyJpIjoiMGQzZj...
)
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Components: hibernate-core
Created: 14/Apr/2023 07:33 AM Priority: Minor Reporter: Staffan Hörke (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
)
Given an entity with an embedded id and a recursive parent/child relationship, when
querying a child instance with a join fetch to the parent, the child instance is populated
with values that belongs to the parent instance.
*Domain model*
@Entity(name = "OrganizationWithEmbeddedId" )
public static class OrganizationWithEmbeddedId {
@EmbeddedId
private OrganizationId id;
private String name;
@ManyToOne
private OrganizationWithEmbeddedId parent;
@OneToMany(mappedBy = "parent" )
private Set<OrganizationWithEmbeddedId> children;
public OrganizationWithEmbeddedId() {
}
public OrganizationWithEmbeddedId(OrganizationId id, String name) {
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
public void setName( String name) {
this.name = name;
}
public OrganizationWithEmbeddedId getParent() {
return parent;
}
public void setParent(OrganizationWithEmbeddedId parent) {
this.parent = parent;
}
public Set<OrganizationWithEmbeddedId> getChildren() {
return children;
}
public void addChild(OrganizationWithEmbeddedId child) {
if (children == null ) {
children = new HashSet<>();
}
children.add(child);
child.setParent( this );
}
@Override
public boolean equals( Object o) {
if ( this == o) return true ;
if (o == null || getClass() != o.getClass()) return false ;
OrganizationWithEmbeddedId that = (OrganizationWithEmbeddedId) o;
return Objects.equals(id, that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}
@Embeddable
public static class OrganizationId implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "id" )
private long value;
OrganizationId() {
super ();
}
OrganizationId( long value) {
this.value = value;
}
@Override
public String toString() {
return Long.toString(value);
}
@Override
public boolean equals( Object o) {
if ( this == o) return true ;
if (o == null || getClass() != o.getClass()) return false ;
OrganizationId that = (OrganizationId) o;
return value == that.value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}
*Query*
SELECT child
FROM OrganizationWithEmbeddedId child
JOIN FETCH child.parent
WHERE child.id = :id
*Result*
The name property of the child instance is wrong. It has the value from the parent
instance.
(
https://hibernate.atlassian.net/browse/HHH-16473#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16473#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#100221- sha1:8830b7c )