Fix unfetched collection assembling

This commit is contained in:
Andrea Boriero 2021-10-13 14:44:04 +02:00
parent d616f2aa55
commit dcab4bf7bf
2 changed files with 56 additions and 2 deletions

View File

@ -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(

View File

@ -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();
}
}