From b27208064544fae55aca1ea1ba92ed2d1f3c2ba6 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 9 Jun 2015 15:25:56 -0500 Subject: [PATCH] HHH-9859 - ResourceLocalTransactionCoordinatorImpl#isJoined bad impl --- ...sourceLocalTransactionCoordinatorImpl.java | 4 +- ...st.java => JtaTransactionJoiningTest.java} | 2 +- .../ResourceLocalTransactionJoiningTest.java | 67 +++++++++++++++++++ .../transaction/TransactionJoiningTest.java | 2 +- 4 files changed, 71 insertions(+), 4 deletions(-) rename hibernate-core/src/test/java/org/hibernate/test/jpa/txn/{TransactionJoiningTest.java => JtaTransactionJoiningTest.java} (98%) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/jpa/txn/ResourceLocalTransactionJoiningTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcResourceLocalTransactionCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcResourceLocalTransactionCoordinatorImpl.java index ecae7d6479..4760db74bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcResourceLocalTransactionCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcResourceLocalTransactionCoordinatorImpl.java @@ -83,8 +83,8 @@ public class JdbcResourceLocalTransactionCoordinatorImpl implements TransactionC @Override public boolean isJoined() { - log.debug( "Calling TransactionCoordinator#isJoined in resource-local mode always returns false" ); - return isActive(); + return physicalTransactionDelegate != null && physicalTransactionDelegate.getStatus() == TransactionStatus.ACTIVE; + } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/TransactionJoiningTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/JtaTransactionJoiningTest.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/jpa/txn/TransactionJoiningTest.java rename to hibernate-core/src/test/java/org/hibernate/test/jpa/txn/JtaTransactionJoiningTest.java index f5b016d0c5..75ff3e9884 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/TransactionJoiningTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/JtaTransactionJoiningTest.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertTrue; /** * @author Steve Ebersole */ -public class TransactionJoiningTest extends AbstractJPATest { +public class JtaTransactionJoiningTest extends AbstractJPATest { @Override public void configure(Configuration cfg) { super.configure( cfg ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/ResourceLocalTransactionJoiningTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/ResourceLocalTransactionJoiningTest.java new file mode 100644 index 0000000000..a6df5a0d1b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/txn/ResourceLocalTransactionJoiningTest.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.jpa.txn; + +import org.hibernate.Session; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; +import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl; +import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jta.TestingJtaBootstrap; +import org.hibernate.testing.junit4.ExtraAssertions; +import org.hibernate.test.jpa.AbstractJPATest; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * @author Steve Ebersole + */ +public class ResourceLocalTransactionJoiningTest extends AbstractJPATest { + @Override + public void configure(Configuration cfg) { + super.configure( cfg ); + TestingJtaBootstrap.prepare( cfg.getProperties() ); + cfg.setProperty( + AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, + JdbcResourceLocalTransactionCoordinatorBuilderImpl.class.getName() + ); + } + + @Test + @TestForIssue( jiraKey = "HHH-9859" ) + public void testExpectations() { + // JPA spec is very vague on what should happen here. It does vaguely + // imply that javax.persistence.EntityManager.joinTransaction() should only be used + // for JTA EMs, however it does not enforced that nor does the TCK check that. + // And the TCK in fact does test calls to javax.persistence.EntityManager.isJoinedToTransaction() + // from resource-local EMs, so lets make sure those work.. + + Session session = sessionFactory().openSession(); + JdbcResourceLocalTransactionCoordinatorImpl tc = ExtraAssertions.assertTyping( + JdbcResourceLocalTransactionCoordinatorImpl.class, + ( (SessionImplementor) session ).getTransactionCoordinator() + ); + assertFalse( tc.isJoined() ); + + session.beginTransaction(); + tc = ExtraAssertions.assertTyping( + JdbcResourceLocalTransactionCoordinatorImpl.class, + ( (SessionImplementor) session ).getTransactionCoordinator() + ); + assertTrue( tc.isJoined() ); + + session.getTransaction().rollback(); + session.close(); + } +} diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java index c43ff816f8..c36f0241d2 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/transaction/TransactionJoiningTest.java @@ -31,7 +31,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** - * Largely a copy of {@link org.hibernate.test.jpa.txn.TransactionJoiningTest} + * Largely a copy of {@link org.hibernate.test.jpa.txn.JtaTransactionJoiningTest} * * @author Steve Ebersole */