Bytecode enhamcement fix unnecessary query for an optional OneToOne
This commit is contained in:
parent
47605bf93b
commit
9d8fbfb727
|
@ -1608,10 +1608,16 @@ public class MappingModelCreationHelper {
|
|||
final FetchTiming fetchTiming;
|
||||
|
||||
final boolean lazy = value.isLazy();
|
||||
if ( lazy
|
||||
&& value.isUnwrapProxy()
|
||||
&& entityPersister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
|
||||
fetchTiming = FetchTiming.DELAYED;
|
||||
if ( lazy && entityPersister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
|
||||
if ( value.isUnwrapProxy() ) {
|
||||
fetchTiming = FetchOptionsHelper.determineFetchTiming( fetchStyle, type, sessionFactory );
|
||||
}
|
||||
else if ( value instanceof ManyToOne && value.isNullable() && ( (ManyToOne) value ).isIgnoreNotFound() ) {
|
||||
fetchTiming = FetchTiming.IMMEDIATE;
|
||||
}
|
||||
else {
|
||||
fetchTiming = FetchOptionsHelper.determineFetchTiming( fetchStyle, type, sessionFactory );
|
||||
}
|
||||
}
|
||||
else if ( fetchStyle == FetchStyle.JOIN
|
||||
|| !lazy
|
||||
|
|
|
@ -53,7 +53,7 @@ public class EntityDelayedFetchImpl extends AbstractNonJoinedEntityFetch {
|
|||
getEntityValuedModelPart(),
|
||||
() -> new EntityDelayedFetchInitializer(
|
||||
navigablePath,
|
||||
(ToOneAttributeMapping) getEntityValuedModelPart(),
|
||||
getEntityValuedModelPart(),
|
||||
keyResult.createResultAssembler( creationState )
|
||||
)
|
||||
);
|
||||
|
|
|
@ -83,6 +83,7 @@ public class FetchGraphTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
assert !Hibernate.isPropertyInitialized( entityD, "e" );
|
||||
|
||||
entityD.getE();
|
||||
|
||||
assertThat( stats.getPrepareStatementCount(), is( 2L ) );
|
||||
assert Hibernate.isPropertyInitialized( entityD, "a" );
|
||||
assert !Hibernate.isInitialized( entityD.getA() );
|
||||
|
|
Loading…
Reference in New Issue