From aae670b9b33dca97ac9624eac3e62ca23532663c Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Sat, 17 Aug 2019 15:53:07 +0100 Subject: [PATCH] HHH-13587 Allocate StatefulPersistenceContext#nullAssociations lazily --- .../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 969c246784..b8cde15c70 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 @@ -176,7 +176,6 @@ public class StatefulPersistenceContext implements PersistenceContext { collectionsByKey = new HashMap<>( INIT_COLL_SIZE ); arrayHolders = new IdentityHashMap<>( INIT_COLL_SIZE ); - nullAssociations = new HashSet<>( INIT_COLL_SIZE ); nonlazyCollections = new ArrayList<>( INIT_COLL_SIZE ); } @@ -1359,16 +1358,19 @@ public class StatefulPersistenceContext implements PersistenceContext { @Override public void addNullProperty(EntityKey ownerKey, String propertyName) { + if ( nullAssociations == null ) { + nullAssociations = new HashSet<>( INIT_COLL_SIZE ); + } nullAssociations.add( new AssociationKey( ownerKey, propertyName ) ); } @Override public boolean isPropertyNull(EntityKey ownerKey, String propertyName) { - return nullAssociations.contains( new AssociationKey( ownerKey, propertyName ) ); + return nullAssociations != null && nullAssociations.contains( new AssociationKey( ownerKey, propertyName ) ); } private void clearNullProperties() { - nullAssociations.clear(); + nullAssociations = null; } @Override