From 88a5fd4d286bd0085557120ad0685f3715043c08 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 21 Feb 2023 17:40:02 +0100 Subject: [PATCH] HHH-16191 Fix eager associations not fetched with native queries --- .../query/results/implicit/ImplicitFetchBuilderEntity.java | 2 +- .../query/results/implicit/ImplicitFetchBuilderPlural.java | 2 +- .../main/java/org/hibernate/sql/results/graph/FetchList.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java index cbc0a866ba..79cf2f5234 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderEntity.java @@ -130,7 +130,7 @@ public class ImplicitFetchBuilderEntity implements ImplicitFetchBuilder { final Fetch fetch = parent.generateFetchableFetch( fetchable, fetchPath, - FetchTiming.DELAYED, + fetchable.getMappedFetchOptions().getTiming(), false, null, creationState diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderPlural.java b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderPlural.java index 35e68da8bc..1fb7813b2e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderPlural.java +++ b/hibernate-core/src/main/java/org/hibernate/query/results/implicit/ImplicitFetchBuilderPlural.java @@ -52,7 +52,7 @@ public class ImplicitFetchBuilderPlural implements ImplicitFetchBuilder { final Fetch fetch = parent.generateFetchableFetch( fetchable, fetchPath, - FetchTiming.DELAYED, + fetchable.getMappedFetchOptions().getTiming(), false, null, creationState diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchList.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchList.java index 654767ee98..273a0dd4b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchList.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/FetchList.java @@ -16,6 +16,7 @@ import org.hibernate.internal.util.IndexedConsumer; import org.hibernate.sql.results.graph.basic.BasicFetch; import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch; import org.hibernate.sql.results.graph.embeddable.EmbeddableResultGraphNode; +import org.hibernate.sql.results.graph.entity.internal.AbstractNonJoinedEntityFetch; /** * This is essentially a List of Fetch(es), but exposing @@ -50,7 +51,7 @@ public interface FetchList extends Iterable { default boolean hasJoinFetches() { for ( Fetch fetch : this ) { - if ( fetch instanceof BasicFetch || fetch.getTiming() == FetchTiming.DELAYED ) { + if ( fetch instanceof BasicFetch || fetch instanceof AbstractNonJoinedEntityFetch || fetch.getTiming() == FetchTiming.DELAYED ) { // That's fine } else if ( fetch instanceof EmbeddableResultGraphNode ) {