From cf189164445cb2ac82265e7f13d2071eb2d8bc25 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 6 Nov 2018 19:03:13 -0800 Subject: [PATCH] HHH-11209 : Log a DEBUG message if collection with queued operations is detached due to rollback (cherry picked from commit 7af7182cc1b2d3ec390d3f64a913a952767b8191) --- .../internal/AbstractPersistentCollection.java | 16 +++++++++++++++- .../hibernate/internal/CoreMessageLogger.java | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java index 54f714770f..633b7c2c4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java @@ -38,6 +38,7 @@ import org.hibernate.internal.util.collections.IdentitySet; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; +import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.type.CompositeType; import org.hibernate.type.IntegerType; import org.hibernate.type.LongType; @@ -625,7 +626,20 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers if ( currentSession == this.session ) { if ( !isTempSession ) { if ( hasQueuedOperations() ) { - LOG.queuedOperationWhenDetachFromSession( MessageHelper.collectionInfoString( getRole(), getKey() ) ); + final String collectionInfoString = MessageHelper.collectionInfoString( getRole(), getKey() ); + final TransactionStatus transactionStatus = + session.getTransactionCoordinator().getTransactionDriverControl().getStatus(); + if ( transactionStatus.isOneOf( + TransactionStatus.ROLLED_BACK, + TransactionStatus.MARKED_ROLLBACK, + TransactionStatus.FAILED_COMMIT, + TransactionStatus.FAILED_ROLLBACK, + TransactionStatus.ROLLING_BACK + ) ) + LOG.queuedOperationWhenDetachFromSessionOnRollback( collectionInfoString ); + else { + LOG.queuedOperationWhenDetachFromSession( collectionInfoString ); + } } this.session = null; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 745f8d87c2..df3d26807f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -1826,4 +1826,8 @@ public interface CoreMessageLogger extends BasicLogger { @LogMessage(level = WARN) @Message(value = "Detaching an uninitialized collection with queued operations from a session: %s", id = 496) void queuedOperationWhenDetachFromSession(String collectionInfoString); + + @LogMessage(level = DEBUG) + @Message(value = "Detaching an uninitialized collection with queued operations from a session due to rollback: %s", id = 498) + void queuedOperationWhenDetachFromSessionOnRollback(String collectionInfoString); }