From c88cdaff96805c49bc4c3a326d97e87aef70addd Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 23 May 2011 11:48:49 -0500 Subject: [PATCH] HHH-6247 - Log (warn) inability for EM to join transaction only when user explicitly asked for join --- .../ejb/AbstractEntityManagerImpl.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java index 1afec53351..bd4a6f296b 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java @@ -88,13 +88,13 @@ import org.hibernate.ejb.internal.EntityManagerMessageLogger; import org.hibernate.ejb.util.CacheModeHelper; import org.hibernate.ejb.util.ConfigurationHelper; import org.hibernate.ejb.util.LockModeTypeHelper; -import org.hibernate.engine.query.spi.HQLQueryPlan; -import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.ResultSetMappingDefinition; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.query.spi.HQLQueryPlan; import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; import org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn; +import org.hibernate.engine.spi.NamedSQLQueryDefinition; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.engine.transaction.spi.JoinStatus; import org.hibernate.engine.transaction.spi.TransactionCoordinator; @@ -1163,9 +1163,9 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage throw new PersistenceException( "Hibernate cannot unwrap " + clazz ); } - private void joinTransaction(boolean ignoreNotJoining) { + private void joinTransaction(boolean explicitRequest) { if ( transactionType != PersistenceUnitTransactionType.JTA ) { - if ( !ignoreNotJoining ) { + if ( explicitRequest ) { LOG.callingJoinTransactionOnNonJtaEntityManager(); } return; @@ -1180,11 +1180,14 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage LOG.debug( "Looking for a JTA transaction to join" ); if ( ! transactionCoordinator.isTransactionJoinable() ) { - LOG.unableToJoinTransaction(Environment.TRANSACTION_STRATEGY); + if ( explicitRequest ) { + // if this is an explicit join request, log a warning so user can track underlying cause + // of subsequent exceptions/messages + LOG.unableToJoinTransaction(Environment.TRANSACTION_STRATEGY); + } } try { - if ( transaction.getJoinStatus() == JoinStatus.JOINED ) { LOG.debug( "Transaction already joined" ); return; // noop @@ -1193,12 +1196,12 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage // join the transaction and then recheck the status transaction.join(); if ( transaction.getJoinStatus() == JoinStatus.NOT_JOINED ) { - if ( ignoreNotJoining ) { - LOG.debug( "No JTA transaction found" ); - return; + if ( explicitRequest ) { + throw new TransactionRequiredException( "No active JTA transaction on joinTransaction call" ); } else { - throw new TransactionRequiredException( "No active JTA transaction on joinTransaction call" ); + LOG.debug( "Unable to join JTA transaction" ); + return; } } else if ( transaction.getJoinStatus() == JoinStatus.MARKED_FOR_JOINED ) {