|
| 1 | +/* |
| 2 | + * Hibernate, Relational Persistence for Idiomatic Java |
| 3 | + * |
| 4 | + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. |
| 5 | + * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 6 | + */ |
| 7 | +package org.hibernate.test.jpa.txn; |
| 8 | + |
| 9 | +import org.hibernate.Session; |
| 10 | +import org.hibernate.cfg.AvailableSettings; |
| 11 | +import org.hibernate.cfg.Configuration; |
| 12 | +import org.hibernate.engine.spi.SessionImplementor; |
| 13 | +import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; |
| 14 | +import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl; |
| 15 | +import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; |
| 16 | + |
| 17 | +import org.hibernate.testing.TestForIssue; |
| 18 | +import org.hibernate.testing.jta.TestingJtaBootstrap; |
| 19 | +import org.hibernate.testing.junit4.ExtraAssertions; |
| 20 | +import org.hibernate.test.jpa.AbstractJPATest; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import static org.junit.Assert.assertFalse; |
| 25 | +import static org.junit.Assert.assertTrue; |
| 26 | + |
| 27 | +/** |
| 28 | + * @author Steve Ebersole |
| 29 | + */ |
| 30 | +public class ResourceLocalTransactionJoiningTest extends AbstractJPATest { |
| 31 | + @Override |
| 32 | + public void configure(Configuration cfg) { |
| 33 | + super.configure( cfg ); |
| 34 | + TestingJtaBootstrap.prepare( cfg.getProperties() ); |
| 35 | + cfg.setProperty( |
| 36 | + AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, |
| 37 | + JdbcResourceLocalTransactionCoordinatorBuilderImpl.class.getName() |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + @TestForIssue( jiraKey = "HHH-9859" ) |
| 43 | + public void testExpectations() { |
| 44 | + // JPA spec is very vague on what should happen here. It does vaguely |
| 45 | + // imply that javax.persistence.EntityManager.joinTransaction() should only be used |
| 46 | + // for JTA EMs, however it does not enforced that nor does the TCK check that. |
| 47 | + // And the TCK in fact does test calls to javax.persistence.EntityManager.isJoinedToTransaction() |
| 48 | + // from resource-local EMs, so lets make sure those work.. |
| 49 | + |
| 50 | + Session session = sessionFactory().openSession(); |
| 51 | + JdbcResourceLocalTransactionCoordinatorImpl tc = ExtraAssertions.assertTyping( |
| 52 | + JdbcResourceLocalTransactionCoordinatorImpl.class, |
| 53 | + ( (SessionImplementor) session ).getTransactionCoordinator() |
| 54 | + ); |
| 55 | + assertFalse( tc.isJoined() ); |
| 56 | + |
| 57 | + session.beginTransaction(); |
| 58 | + tc = ExtraAssertions.assertTyping( |
| 59 | + JdbcResourceLocalTransactionCoordinatorImpl.class, |
| 60 | + ( (SessionImplementor) session ).getTransactionCoordinator() |
| 61 | + ); |
| 62 | + assertTrue( tc.isJoined() ); |
| 63 | + |
| 64 | + session.getTransaction().rollback(); |
| 65 | + session.close(); |
| 66 | + } |
| 67 | +} |
0 commit comments