From dbbc24c2e16bc99606aaf7e17fc3c1b8cabf31c5 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Sat, 17 Aug 2019 21:26:42 +0100 Subject: [PATCH] HHH-13587 Make StatefulPersistenceContext#nonlazyCollections a lazily initialized field --- .../engine/internal/StatefulPersistenceContext.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index b072382e11..f9663713cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -163,8 +163,6 @@ public class StatefulPersistenceContext implements PersistenceContext { entityEntryContext = new EntityEntryContext( this ); collectionsByKey = new HashMap<>( INIT_COLL_SIZE ); arrayHolders = new IdentityHashMap<>( INIT_COLL_SIZE ); - - nonlazyCollections = new ArrayList<>( INIT_COLL_SIZE ); } private ConcurrentMap getOrInitializeProxiesByKey() { @@ -252,6 +250,7 @@ public class StatefulPersistenceContext implements PersistenceContext { parentsByChild = null; entitySnapshotsByKey.clear(); collectionsByKey.clear(); + nonlazyCollections = null; collectionEntries = null; unownedCollections = null; proxiesByKey = null; @@ -952,6 +951,9 @@ public class StatefulPersistenceContext implements PersistenceContext { @Override public void addNonLazyCollection(PersistentCollection collection) { + if ( nonlazyCollections == null ) { + nonlazyCollections = new ArrayList<>( INIT_COLL_SIZE ); + } nonlazyCollections.add( collection ); } @@ -965,7 +967,7 @@ public class StatefulPersistenceContext implements PersistenceContext { loadCounter++; try { int size; - while ( ( size = nonlazyCollections.size() ) > 0 ) { + while ( nonlazyCollections != null && ( size = nonlazyCollections.size() ) > 0 ) { //note that each iteration of the loop may add new elements nonlazyCollections.remove( size - 1 ).forceInitialization(); }