Skip to content

Commit 0297dad

Browse files
committed
HHH-19874 NullPointerException in org.hibernate.sql.ast.tree.from.TableGroup.resolveTableReference
1 parent cd86257 commit 0297dad

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ public EntityHolder claimEntityHolderIfPossible(
405405
else {
406406
newEntityHolder = null;
407407
}
408-
holder.entityInitializer = initializer;
408+
if ( holder.processingState != processingState ) {
409+
holder.entityInitializer = initializer;
410+
holder.processingState = processingState;
411+
}
409412
return holder;
410413
}
411414

@@ -2174,7 +2177,8 @@ private static class EntityHolderImpl implements EntityHolder, Serializable {
21742177
private Object entity;
21752178
private Object proxy;
21762179
private @Nullable EntityEntry entityEntry;
2177-
private EntityInitializer<?> entityInitializer;
2180+
private @Nullable EntityInitializer<?> entityInitializer;
2181+
private @Nullable JdbcValuesSourceProcessingState processingState;
21782182
private EntityHolderState state;
21792183

21802184
private EntityHolderImpl() {
@@ -2212,10 +2216,15 @@ public Object getProxy() {
22122216
}
22132217

22142218
@Override
2215-
public EntityInitializer<?> getEntityInitializer() {
2219+
public @Nullable EntityInitializer<?> getEntityInitializer() {
22162220
return entityInitializer;
22172221
}
22182222

2223+
@Override
2224+
public @Nullable JdbcValuesSourceProcessingState getJdbcValuesProcessingState() {
2225+
return processingState;
2226+
}
2227+
22192228
@Override
22202229
public void markAsReloaded(JdbcValuesSourceProcessingState processingState) {
22212230
processingState.registerReloadedEntityHolder( this );
@@ -2237,8 +2246,9 @@ public boolean isDetached() {
22372246
}
22382247

22392248
@Override
2240-
public void resetEntityInitialier(){
2249+
public void resetEntityInitialier() {
22412250
entityInitializer = null;
2251+
processingState = null;
22422252
}
22432253

22442254
public EntityHolderImpl withEntity(EntityKey entityKey, EntityPersister descriptor, Object entity) {
@@ -2253,6 +2263,7 @@ public EntityHolderImpl withData(EntityKey entityKey, EntityPersister descriptor
22532263
assert entityKey != null
22542264
&& descriptor != null
22552265
&& entityInitializer == null
2266+
&& processingState == null
22562267
&& state == EntityHolderState.UNINITIALIZED;
22572268
this.entityKey = entityKey;
22582269
this.descriptor = descriptor;

hibernate-core/src/main/java/org/hibernate/engine/spi/EntityHolder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public interface EntityHolder {
3535
* Will be {@code null} if entity is initialized already or the entity holder is not claimed yet.
3636
*/
3737
@Nullable EntityInitializer<?> getEntityInitializer();
38+
/**
39+
* The {@link JdbcValuesSourceProcessingState} for the entity initializer that claims to initialize the entity for this holder.
40+
* Will be {@code null} if entity is initialized already or the entity holder is not claimed yet.
41+
*/
42+
@Nullable JdbcValuesSourceProcessingState getJdbcValuesProcessingState();
3843

3944
/**
4045
* The proxy if there is one and otherwise the entity.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,12 @@ else if ( isResultInitializer() ) {
11871187
}
11881188
}
11891189
else if ( entityHolder.getEntityInitializer() != this ) {
1190-
data.setState( State.INITIALIZED );
1190+
// The other initializer will take care of initialization
1191+
if ( !hasLazyInitializingSubAssemblers ) {
1192+
// but we can only skip the initialization phase of this initializer,
1193+
// if this initializer does not initialize lazy basic attributes
1194+
data.setState( State.INITIALIZED );
1195+
}
11911196
}
11921197
else if ( data.shallowCached ) {
11931198
// For shallow cached entities, only the id is available, so ensure we load the data immediately

0 commit comments

Comments
 (0)