Skip to content

Commit

Permalink
EntityFetchDelayedInitializer check if a Proxy already exists before …
Browse files Browse the repository at this point in the history
…creating a new one
  • Loading branch information
dreab8 committed Mar 9, 2020
1 parent a96096b commit 956da85
Showing 1 changed file with 16 additions and 5 deletions.
Expand Up @@ -10,6 +10,7 @@

import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.NavigablePath;
import org.hibernate.sql.results.graph.AbstractFetchParentAccess;
Expand Down Expand Up @@ -63,7 +64,8 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
}
else {
final EntityKey entityKey = new EntityKey( identifier, concreteDescriptor );
final Object entity = rowProcessingState.getSession().getPersistenceContext().getEntity( entityKey );
PersistenceContext persistenceContext = rowProcessingState.getSession().getPersistenceContext();
final Object entity = persistenceContext.getEntity( entityKey );
if ( entity != null ) {
entityInstance = entity;
}
Expand All @@ -74,10 +76,19 @@ public void resolveInstance(RowProcessingState rowProcessingState) {
entityInstance = loadingEntityLocally.getEntityInstance();
}
else if ( concreteDescriptor.hasProxy() ) {
entityInstance = concreteDescriptor.createProxy(
identifier,
rowProcessingState.getSession()
);
final Object proxy = persistenceContext.getProxy( entityKey );
if ( proxy != null ) {
entityInstance = proxy;
}
else {
entityInstance = concreteDescriptor.createProxy(
identifier,
rowProcessingState.getSession()
);
persistenceContext
.getBatchFetchQueue().addBatchLoadableEntityKey( entityKey );
persistenceContext.addProxy( entityKey, entityInstance );
}
}
else if ( concreteDescriptor
.getBytecodeEnhancementMetadata()
Expand Down

0 comments on commit 956da85

Please sign in to comment.