[JIRA] (HHH-15628) OneToOne relationship is null when hibernate.max_fetch_depth = 1
by Mike Conner (JIRA)
Mike Conner ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=62fe3d3... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOTgwMTczYTIw... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15628?atlOrigin=eyJpIjoiOTgwMT... ) HHH-15628 ( https://hibernate.atlassian.net/browse/HHH-15628?atlOrigin=eyJpIjoiOTgwMT... ) OneToOne relationship is null when hibernate.max_fetch_depth = 1 ( https://hibernate.atlassian.net/browse/HHH-15628?atlOrigin=eyJpIjoiOTgwMT... )
Issue Type: Bug Affects Versions: 6.1.4 Assignee: Unassigned Components: query-hql Created: 25/Oct/2022 11:34 AM Environment: Hibernate 6.1.4,
$ java -version
openjdk version "17.0.4" 2022-07-19 LTS
OpenJDK Runtime Environment Corretto-17.0.4.8.1 (build 17.0.4+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.4.8.1 (build 17.0.4+8-LTS, mixed mode, sharing)
Originally Oracle 19c, test case using H2: com.h2database:h2:2.1.214
Priority: Major Reporter: Mike Conner ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=62fe3d3... )
Given entities: Device, DeviceClientId, DeviceServerId, DevPart
Where Device has mappings to the two Device_Xxx_Id entities as:
@OneToOne(targetEntity = DevClientId.class, mappedBy = "device", cascade = {
CascadeType.ALL }, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private DevClientId devClientId;
And DevPart is mapped as:
@OneToMany(targetEntity = DevPart.class, mappedBy = "device", fetch = FetchType.EAGER)
private Set<DevPart> devParts;
Both The Device_Xxx_Id entities map the Device as:
@OneToOne(targetEntity = Device.class, fetch = FetchType.EAGER)
@JoinColumn(name = "DEVICE_FK" , nullable = false )
private Device device;
if hibernate.max_fetch_depth = 1, then a query of the devices results in the clientId and the serverId being null. even though it executes a query for the both the client a server ids. The attached test case outputs the following error:
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:87)
at org.junit.Assert.assertTrue(Assert.java:42)
at org.junit.Assert.assertNotNull(Assert.java:713)
at org.junit.Assert.assertNotNull(Assert.java:723)
at org.hibernate.bugs.JPAUnitTestCase.testOneToOneTwoWayMapping(JPAUnitTestCase.java:79)
Prior to that, it executes sql to get the clientID and does extract data:
13:12:00.362 [main] DEBUG org.hibernate.SQL -
select
d1_0.pk,
d2_0.pk,
d2_0.name,
d1_0.name
from
DEV_CLIENT_ID_T d1_0
join
DEVICE_T d2_0
on d2_0.pk=d1_0.DEVICE_FK
where
d1_0.DEVICE_FK=?
13:12:00.364 [main] TRACE org.hibernate.orm.jdbc.bind - binding parameter [1] as [BIGINT] - [1000]
13:12:00.364 [main] TRACE org.hibernate.orm.jdbc.extract - extracted value ([1] : [BIGINT]) - [1101]
13:12:00.365 [main] TRACE org.hibernate.orm.jdbc.extract - extracted value ([2] : [BIGINT]) - [1000]
13:12:00.365 [main] TRACE org.hibernate.orm.jdbc.extract - extracted value ([3] : [VARCHAR]) - [device1]
13:12:00.365 [main] TRACE org.hibernate.orm.jdbc.extract - extracted value ([4] : [VARCHAR]) - [device1ClientId]
but never sets it on the Device. If hibernate.max_fetch_depth is set to 2, then this works. This used to work in 5.3.28.
Also, for some reason, if I remove the DevPart class and mapping entirely, the test again fails to load the DevClientID and DevServerID into the Device, but this time it fails regardless of the {{hibernate.max_fetch_depth }}value.
( https://hibernate.atlassian.net/browse/HHH-15628#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15628#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100209- sha1:9aa9d1d )
2 years, 11 months