Skip to content

Commit 7fcdb3e

Browse files
committed
HHH-19734 Ensure shallow cached entity is not left uninitialized when bytecode enhanced
1 parent 39267cb commit 7fcdb3e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityInitializerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,10 @@ else if ( isResultInitializer() ) {
11181118
else if ( data.entityHolder.getEntityInitializer() != this ) {
11191119
data.setState( State.INITIALIZED );
11201120
}
1121+
else if ( data.shallowCached ) {
1122+
// For shallow cached entities, only the id is available, so ensure we load the data immediately
1123+
data.setInstance( data.entityInstanceForNotify = resolveEntityInstance( data ) );
1124+
}
11211125
}
11221126
else if ( ( entityFromExecutionContext = getEntityFromExecutionContext( data ) ) != null ) {
11231127
// This is the entity to refresh, so don't set the state to initialized
@@ -1231,7 +1235,7 @@ protected Object resolveEntityInstance(EntityInitializerData data) {
12311235
return resolved;
12321236
}
12331237
else {
1234-
if ( rowProcessingState.isQueryCacheHit() && entityDescriptor.useShallowQueryCacheLayout() ) {
1238+
if ( data.shallowCached ) {
12351239
// We must load the entity this way, because the query cache entry contains only the primary key
12361240
data.setState( State.INITIALIZED );
12371241
final SharedSessionContractImplementor session = rowProcessingState.getSession();

0 commit comments

Comments
 (0)