From 6c690f561c002a66e473274b98b82573288c2af3 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 22 Jan 2024 19:35:20 +0100 Subject: [PATCH] HHH-16960 OneToOne lazy loading fails when fetch graph is involved --- .../metamodel/mapping/internal/ToOneAttributeMapping.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java index 824e1c8756..a30f447436 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ToOneAttributeMapping.java @@ -1630,9 +1630,12 @@ public class ToOneAttributeMapping final boolean selectByUniqueKey = isSelectByUniqueKey( side ); // Consider all associations annotated with @NotFound as EAGER + // and LAZY one-to-one that are not instrumented and not optional if ( fetchTiming == FetchTiming.IMMEDIATE || hasNotFoundAction() - || getAssociatedEntityMappingType().getSoftDeleteMapping() != null ) { + || getAssociatedEntityMappingType().getSoftDeleteMapping() != null + || ( !entityMappingType.getEntityPersister().isInstrumented() + && cardinality == Cardinality.ONE_TO_ONE && isOptional ) ) { return buildEntityFetchSelect( fetchParent, this,