From 001de2b203918dba8ca9e66b04c65fb634d09d0a Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Tue, 1 Nov 2022 16:42:21 +0000 Subject: [PATCH] HHH-15651 Logging guard improvements in StatefulPersistenceContext --- .../internal/StatefulPersistenceContext.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 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 79bed00aa2..e75885631d 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 @@ -1376,7 +1376,10 @@ public class StatefulPersistenceContext implements PersistenceContext { final EntityPersister persister = metamodel.getEntityDescriptor( entity ); final CollectionPersister cp = metamodel.getCollectionDescriptor( entity + '.' + property ); - // try cache lookup first + //Extracted as we're logging within two hot loops + final boolean debugEnabled = LOG.isDebugEnabled(); + + // try cache lookup first final Object parent = getParentsByChild( childEntity ); if ( parent != null ) { final EntityEntry entityEntry = entityEntryContext.getEntityEntry( parent ); @@ -1389,10 +1392,12 @@ public class StatefulPersistenceContext implements PersistenceContext { final Object unMergedChild = mergeMap.get( childEntity ); if ( unMergedInstance != null && unMergedChild != null ) { index = getIndexInParent( property, unMergedChild, persister, cp, unMergedInstance ); - LOG.debugf( - "A detached object being merged (corresponding to a parent in parentsByChild) has an indexed collection that [%s] the detached child being merged. ", - ( index != null ? "contains" : "does not contain" ) - ); + if ( debugEnabled ) { + LOG.debugf( + "A detached object being merged (corresponding to a parent in parentsByChild) has an indexed collection that [%s] the detached child being merged. ", + ( index != null ? "contains" : "does not contain" ) + ); + } } } if ( index != null ) { @@ -1417,10 +1422,12 @@ public class StatefulPersistenceContext implements PersistenceContext { final Object unMergedChild = mergeMap.get( childEntity ); if ( unMergedInstance != null && unMergedChild!=null ) { index = getIndexInParent( property, unMergedChild, persister, cp, unMergedInstance ); - LOG.debugf( - "A detached object being merged (corresponding to a managed entity) has an indexed collection that [%s] the detached child being merged. ", - (index != null ? "contains" : "does not contain" ) - ); + if ( debugEnabled ) { + LOG.debugf( + "A detached object being merged (corresponding to a managed entity) has an indexed collection that [%s] the detached child being merged. ", + (index != null ? "contains" : "does not contain" ) + ); + } } }