diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionFetch.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionFetch.java index 305f5937b8..f3fe1b9b51 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionFetch.java @@ -14,7 +14,6 @@ import org.hibernate.sql.results.graph.DomainResult; import org.hibernate.sql.results.graph.DomainResultAssembler; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.FetchParentAccess; -import org.hibernate.sql.results.graph.UnfetchedResultAssembler; import org.hibernate.type.descriptor.java.JavaType; /** @@ -39,7 +38,12 @@ public class DelayedCollectionFetch extends CollectionFetch { AssemblerCreationState creationState) { // lazy attribute if ( collectionKeyResult == null ) { - return new UnfetchedResultAssembler<>( getResultJavaTypeDescriptor() ); + return new UnfetchedCollectionAssembler( + getNavigablePath(), + getFetchedMapping(), + parentAccess, + creationState + ); } else { return new DelayedCollectionAssembler( diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/UnfetchedCollectionAssembler.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/UnfetchedCollectionAssembler.java new file mode 100644 index 0000000000..e867d44d55 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/UnfetchedCollectionAssembler.java @@ -0,0 +1,50 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.sql.results.graph.collection.internal; + +import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; +import org.hibernate.query.NavigablePath; +import org.hibernate.sql.results.graph.AssemblerCreationState; +import org.hibernate.sql.results.graph.DomainResultAssembler; +import org.hibernate.sql.results.graph.FetchParentAccess; +import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions; +import org.hibernate.sql.results.jdbc.spi.RowProcessingState; +import org.hibernate.type.descriptor.java.JavaType; + +public class UnfetchedCollectionAssembler implements DomainResultAssembler { + private final PluralAttributeMapping fetchedMapping; + + public UnfetchedCollectionAssembler( + NavigablePath fetchPath, + PluralAttributeMapping fetchedMapping, + FetchParentAccess parentAccess, + AssemblerCreationState creationState) { + this.fetchedMapping = fetchedMapping; + creationState.resolveInitializer( + fetchPath, + fetchedMapping, + () -> new DelayedCollectionInitializer( + fetchPath, + fetchedMapping, + parentAccess, + null + ) + + ); + } + + @Override + public Object assemble(RowProcessingState rowProcessingState, JdbcValuesSourceProcessingOptions options) { + return LazyPropertyInitializer.UNFETCHED_PROPERTY; + } + + @Override + public JavaType getAssembledJavaTypeDescriptor() { + return fetchedMapping.getJavaTypeDescriptor(); + } +}