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 FetchTiming fetchTiming;
|
||||||
|
|
||||||
final boolean lazy = value.isLazy();
|
final boolean lazy = value.isLazy();
|
||||||
if ( lazy
|
if ( lazy && entityPersister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
|
||||||
&& value.isUnwrapProxy()
|
if ( value.isUnwrapProxy() ) {
|
||||||
&& entityPersister.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) {
|
fetchTiming = FetchOptionsHelper.determineFetchTiming( fetchStyle, type, sessionFactory );
|
||||||
fetchTiming = FetchTiming.DELAYED;
|
}
|
||||||
|
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
|
else if ( fetchStyle == FetchStyle.JOIN
|
||||||
|| !lazy
|
|| !lazy
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class EntityDelayedFetchImpl extends AbstractNonJoinedEntityFetch {
|
||||||
getEntityValuedModelPart(),
|
getEntityValuedModelPart(),
|
||||||
() -> new EntityDelayedFetchInitializer(
|
() -> new EntityDelayedFetchInitializer(
|
||||||
navigablePath,
|
navigablePath,
|
||||||
(ToOneAttributeMapping) getEntityValuedModelPart(),
|
getEntityValuedModelPart(),
|
||||||
keyResult.createResultAssembler( creationState )
|
keyResult.createResultAssembler( creationState )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class FetchGraphTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
assert !Hibernate.isPropertyInitialized( entityD, "e" );
|
assert !Hibernate.isPropertyInitialized( entityD, "e" );
|
||||||
|
|
||||||
entityD.getE();
|
entityD.getE();
|
||||||
|
|
||||||
assertThat( stats.getPrepareStatementCount(), is( 2L ) );
|
assertThat( stats.getPrepareStatementCount(), is( 2L ) );
|
||||||
assert Hibernate.isPropertyInitialized( entityD, "a" );
|
assert Hibernate.isPropertyInitialized( entityD, "a" );
|
||||||
assert !Hibernate.isInitialized( entityD.getA() );
|
assert !Hibernate.isInitialized( entityD.getA() );
|
||||||
|
|
Loading…
Reference in New Issue