From d6108fa1e4b02ef6b5f4f57de27486811afd1385 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Thu, 29 Oct 2020 16:50:06 +0000 Subject: [PATCH] HHH-14305 Memory optimisation for AbstractPropertyMapping#duplicateIncompatiblePaths --- .../persister/entity/AbstractPropertyMapping.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java index f14cbcab7a..fd37e9955b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractPropertyMapping.java @@ -41,7 +41,11 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AbstractPropertyMapping.class ); private final Map typesByPropertyPath = new HashMap<>(); - private final Set duplicateIncompatiblePaths = new HashSet<>(); + + //This field is only used during initialization, no need for threadsafety: + //FIXME get rid of the field, or at least clear it after boot? Not urgent as we typically won't initialize it at all. + private Set duplicateIncompatiblePaths = null; + private final Map columnsByPropertyPath = new HashMap<>(); private final Map columnReadersByPropertyPath = new HashMap<>(); private final Map columnReaderTemplatesByPropertyPath = new HashMap<>(); @@ -168,7 +172,7 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { String[] formulaTemplates, Mapping factory) { Type existingType = typesByPropertyPath.get( path ); - if ( existingType != null || duplicateIncompatiblePaths.contains( path ) ) { + if ( existingType != null || ( duplicateIncompatiblePaths != null && duplicateIncompatiblePaths.contains( path ) ) ) { // If types match or the new type is not an association type, there is nothing for us to do if ( type == existingType || existingType == null || !( type instanceof AssociationType ) ) { logDuplicateRegistration( path, existingType, type ); @@ -212,6 +216,9 @@ public abstract class AbstractPropertyMapping implements PropertyMapping { logIncompatibleRegistration( path, existingType, type ); } if ( commonType == null ) { + if ( duplicateIncompatiblePaths == null ) { + duplicateIncompatiblePaths = new HashSet<>(); + } duplicateIncompatiblePaths.add( path ); typesByPropertyPath.remove( path ); // Set everything to empty to signal action has to be taken!