I’m migrating a project from Hibernate 5.3.13 to 6.1.4. I’ve got an app that loads a set of entities, which I’ll call EA, where there are two OneToOne mappings to entities I’ll call EB1 and EB2:
EA:
@OneToOne(targetEntity = EB1.class, mappedBy = "ea", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private EB1 eb1;
@OneToOne(targetEntity = EB2.class, mappedBy = "ea", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private EB2 eb2;
EB1:
@OneToOne(targetEntity = EA.class, fetch = FetchType.EAGER)
@JoinColumn(name = "EA_FK", nullable = false)
private EA ea;
And EB2 is similarily mapped to EA. All entities have additional mappings not shown here for brevity.
(If it matters, all these extend the same parent class, which I’ll call P, that is annotated with @MappedSuperclass. In fact, there’s a couple levels of inheritance using @MappedSuperclass, which provide standard PK and a name attributes)
When I do an HQL query to load the EAs: select distinct e from EA as e
It correctly queries for all EAs, but also for each EB1 and EB2 for each of the EA. (So lazy isn’t working, but I gather there’s a quirk to that with OnetoOne mapping, and that isn’t the issue I’m concerned about, at the moment.)
The problem I’m having is that while I can see from the logs that it is executing SQL for the data for EB1, and it is extracting that data (so it is getting results), it is setting each EA.eb1 value to null. (I changed the Access to property: @Access(value= AccessType.PROPERTY)
so that I could log and debug when they are set.) The OneToOne mapping on eb2 works properly.
Some additional info:
- If I remove the second mapping (for EB2), the relationship to EB1 works properly.
- If I instead rename eb1 to zzzEb1 (presumably, it shows up second somewhere along the way), then that works correctly, but eb2 is set to null, instead.
This used to work in 5.3.x. Has something changed in the way this should be mapped?
Thanks