geoffrey deremetz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea439b...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODdiMzliNmZh...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16901?atlOrigin=eyJpIjoiODdiMz...
) HHH-16901 (
https://hibernate.atlassian.net/browse/HHH-16901?atlOrigin=eyJpIjoiODdiMz...
) Hibernate 6 : Embedded field not correctly instantiated (
https://hibernate.atlassian.net/browse/HHH-16901?atlOrigin=eyJpIjoiODdiMz...
)
Change By: geoffrey deremetz (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea439b...
)
Spring boot 3.1.1 - Hibernate 6.2.5.Final
Embedded field are not correctly instantiated when I use entity is used in a composite key
to load my entity
{noformat}@Entity
@Table(name = "trip")
public class Trip {
@Id
public Long id;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "date", column = @Column(name =
"date_position1")),
})
@AssociationOverride(name = "poi", joinColumns = @JoinColumn(name =
"poi1_id_fk"))
public Location position1 = new Location();
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "date", column = @Column(name =
"date_position2")),
})
@AssociationOverride(name = "poi", joinColumns = @JoinColumn(name =
"poi2_id_fk"))
public Location position2 = new Location();
}{noformat}
in certain scenarios (see my code attached), trip.position2 is null when it shouldn't
be ({{poi2_id_fk}} is null but not {{date_position2}})
scenario 1 (working)
{noformat} Trip trip = tripRepository.findById(1L).orElseThrow();
assertThat(trip.position1).isNotNull();
assertThat(trip.position2).isNotNull();{noformat}
scenario 2 (not working)
{noformat} @Entity
@Table(name = "report_trip")
public class ReportTrip {
@EmbeddedId
public ReportTripId compositeKey = new ReportTripId();
@Column(name = "other")
public String other;
}
@Embeddable
public class ReportTripId implements Serializable {
@ManyToOne
@JoinColumn(name = "report_id_fk")
public Report report;
@ManyToOne
@JoinColumn(name = "trip_id_fk")
public Trip trip;
}{noformat}
{noformat} Optional<Report> reportOptional = repository.findById(1L);
assertThat(reportOptional).isPresent();
Report report = reportOptional.get();
assertThat(report.reportTripList.get(0).compositeKey.trip.position1).isNotNull();
assertThat(report.reportTripList.get(0).compositeKey.trip.position2).isNotNull(); //
ko{noformat}
(
https://hibernate.atlassian.net/browse/HHH-16901#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16901#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#100230- sha1:e339e49 )