Skip to content

Commit

Permalink
HHH-15606 @OnetoOne(mappedBy = ..., fetch = LAZY) in embedded leads t…
Browse files Browse the repository at this point in the history
…o IllegalArgumentException: Can not set [...] to LazyPropertyInitializer
  • Loading branch information
dreab8 committed Nov 22, 2022
1 parent e07bbc1 commit 9180519
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hibernate.sql.results.graph.AbstractFetchParentAccess;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.FetchParentAccess;
import org.hibernate.sql.results.graph.embeddable.EmbeddableInitializer;
import org.hibernate.sql.results.graph.entity.AbstractEntityInitializer;
import org.hibernate.sql.results.graph.entity.EntityInitializer;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
Expand Down Expand Up @@ -110,11 +111,10 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
}
}
if ( entityInstance == null ) {
if ( referencedModelPart.isOptional() && parentAccess != null && parentAccess.getInitializedPart()
.findContainingEntityMapping()
.getEntityPersister()
.getBytecodeEnhancementMetadata()
.isEnhancedForLazyLoading() ) {
if ( referencedModelPart.isOptional()
&& parentAccess != null
&& !parentAccess.isEmbeddableInitializer()
&& isEnhancedForLazyLoading( parentAccess ) ) {
entityInstance = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
else {
Expand All @@ -138,9 +138,9 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
entityInstance = persistenceContext.getEntity( euk );
if ( entityInstance == null ) {
if ( ( (AbstractEntityInitializer) this.parentAccess.findFirstEntityDescriptorAccess() ).getEntityDescriptor()
.getBytecodeEnhancementMetadata()
.isEnhancedForLazyLoading() ) {
if ( parentAccess != null
&& !parentAccess.isEmbeddableInitializer()
&& isEnhancedForLazyLoading( parentAccess ) ) {
return;
}
entityInstance = ( (UniqueKeyLoadable) concreteDescriptor ).loadByUniqueKey(
Expand Down Expand Up @@ -179,6 +179,11 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
}
}

private static boolean isEnhancedForLazyLoading(FetchParentAccess parentAccess) {
return parentAccess.findFirstEntityInitializer().getEntityDescriptor().getBytecodeEnhancementMetadata()
.isEnhancedForLazyLoading();
}

@Override
public void initializeInstance(RowProcessingState rowProcessingState) {
// nothing to do
Expand Down

0 comments on commit 9180519

Please sign in to comment.