Skip to content

Commit 862300a

Browse files
committed
HHH-19874 NullPointerException in org.hibernate.sql.ast.tree.from.TableGroup.resolveTableReference
1 parent 43c0df4 commit 862300a

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ public EntityHolder claimEntityHolderIfPossible(
417417
else {
418418
newEntityHolder = null;
419419
}
420-
holder.entityInitializer = initializer;
420+
if ( holder.processingState != processingState ) {
421+
holder.entityInitializer = initializer;
422+
holder.processingState = processingState;
423+
}
421424
return holder;
422425
}
423426

@@ -2193,7 +2196,8 @@ private static class EntityHolderImpl implements EntityHolder, Serializable {
21932196
private Object entity;
21942197
private Object proxy;
21952198
private @Nullable EntityEntry entityEntry;
2196-
private EntityInitializer<?> entityInitializer;
2199+
private @Nullable EntityInitializer<?> entityInitializer;
2200+
private @Nullable JdbcValuesSourceProcessingState processingState;
21972201
private EntityHolderState state;
21982202

21992203
private EntityHolderImpl() {
@@ -2231,10 +2235,15 @@ public Object getProxy() {
22312235
}
22322236

22332237
@Override
2234-
public EntityInitializer<?> getEntityInitializer() {
2238+
public @Nullable EntityInitializer<?> getEntityInitializer() {
22352239
return entityInitializer;
22362240
}
22372241

2242+
@Override
2243+
public @Nullable JdbcValuesSourceProcessingState getJdbcValuesProcessingState() {
2244+
return processingState;
2245+
}
2246+
22382247
@Override
22392248
public void markAsReloaded(JdbcValuesSourceProcessingState processingState) {
22402249
processingState.registerReloadedEntityHolder( this );
@@ -2256,8 +2265,9 @@ public boolean isDetached() {
22562265
}
22572266

22582267
@Override
2259-
public void resetEntityInitialier(){
2268+
public void resetEntityInitialier() {
22602269
entityInitializer = null;
2270+
processingState = null;
22612271
}
22622272

22632273
public EntityHolderImpl withEntity(EntityKey entityKey, EntityPersister descriptor, Object entity) {
@@ -2269,7 +2279,11 @@ public EntityHolderImpl withProxy(EntityKey entityKey, EntityPersister descripto
22692279
}
22702280

22712281
public EntityHolderImpl withData(EntityKey entityKey, EntityPersister descriptor, Object entity, Object proxy) {
2272-
assert entityKey != null && descriptor != null && entityInitializer == null && state == EntityHolderState.UNINITIALIZED;
2282+
assert entityKey != null
2283+
&& descriptor != null
2284+
&& entityInitializer == null
2285+
&& processingState == null
2286+
&& state == EntityHolderState.UNINITIALIZED;
22732287
this.entityKey = entityKey;
22742288
this.descriptor = descriptor;
22752289
this.entity = entity;

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
@@ -1249,7 +1249,12 @@ else if ( isResultInitializer() ) {
12491249
}
12501250
}
12511251
else if ( data.entityHolder.getEntityInitializer() != this ) {
1252-
data.setState( State.INITIALIZED );
1252+
// The other initializer will take care of initialization
1253+
if ( !hasLazyInitializingSubAssemblers ) {
1254+
// but we can only skip the initialization phase of this initializer,
1255+
// if this initializer does not initialize lazy basic attributes
1256+
data.setState( State.INITIALIZED );
1257+
}
12531258
}
12541259
else if ( data.shallowCached ) {
12551260
// For shallow cached entities, only the id is available, so ensure we load the data immediately

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ protected void initialize(
240240
}
241241
}
242242
else if ( holder.getEntityInitializer() != this ) {
243-
// the entity is already being loaded elsewhere
244-
data.setState( State.INITIALIZED );
243+
// the entity is already being loaded elsewhere in this processing level
244+
if ( holder.getJdbcValuesProcessingState() == data.getRowProcessingState().getJdbcValuesSourceProcessingState() ) {
245+
data.setState( State.INITIALIZED );
246+
}
245247
return;
246248
}
247249
else if ( data.getInstance() == null ) {

0 commit comments

Comments
 (0)