diff --git a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java index eec3b10f60..2d6980f38f 100644 --- a/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java @@ -64,9 +64,30 @@ public interface SharedSessionContract extends QueryProducer, Closeable, Seriali * Get the {@link Transaction} instance associated with this session. * * @return a Transaction instance + * + * @see jakarta.persistence.EntityManager#getTransaction() */ Transaction getTransaction(); + /** + * Join the currently-active JTA transaction. + * + * @see jakarta.persistence.EntityManager#joinTransaction() + * + * @since 6.2 + */ + void joinTransaction(); + + /** + * Check if the session is joined to the current transaction. + * + * @see #joinTransaction() + * @see jakarta.persistence.EntityManager#isJoinedToTransaction() + * + * @since 6.2 + */ + boolean isJoinedToTransaction(); + /** * Obtain a {@link ProcedureCall} based on a named template * diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java index ca1f6dc656..17a444e8d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java @@ -284,6 +284,16 @@ public class SharedSessionDelegatorBaseImpl implements SharedSessionContractImpl return delegate.getTransaction(); } + @Override + public void joinTransaction() { + delegate.joinTransaction(); + } + + @Override + public boolean isJoinedToTransaction() { + return delegate.isJoinedToTransaction(); + } + @Override public HibernateCriteriaBuilder getCriteriaBuilder() { return delegate.getCriteriaBuilder(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index d3dd7137af..a697efcc32 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -84,6 +84,7 @@ import org.hibernate.resource.jdbc.internal.EmptyStatementInspector; import org.hibernate.resource.jdbc.spi.JdbcSessionContext; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.resource.jdbc.spi.StatementInspector; +import org.hibernate.resource.transaction.TransactionRequiredForJoinException; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; import org.hibernate.resource.transaction.spi.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; @@ -539,6 +540,31 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } + @Override + public void joinTransaction() { + checkOpen(); + if ( !getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta() ) { + log.callingJoinTransactionOnNonJtaEntityManager(); + return; + } + + try { + getTransactionCoordinator().explicitJoin(); + } + catch ( TransactionRequiredForJoinException e ) { + throw new TransactionRequiredException( e.getMessage() ); + } + catch ( HibernateException he ) { + throw getExceptionConverter().convert( he ); + } + } + + @Override + public boolean isJoinedToTransaction() { + checkOpen(); + return getTransactionCoordinator().isJoined(); + } + protected void delayedAfterCompletion() { if ( transactionCoordinator instanceof JtaTransactionCoordinatorImpl ) { ( (JtaTransactionCoordinatorImpl) transactionCoordinator ) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 7994d046ce..c56f266b67 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -127,7 +127,6 @@ import org.hibernate.query.SelectionQuery; import org.hibernate.query.UnknownSqlResultSetMappingException; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; -import org.hibernate.resource.transaction.TransactionRequiredForJoinException; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; import org.hibernate.resource.transaction.spi.TransactionCoordinator; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; @@ -2748,31 +2747,6 @@ public class SessionImpl } } - @Override - public void joinTransaction() { - checkOpen(); - if ( !getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta() ) { - log.callingJoinTransactionOnNonJtaEntityManager(); - return; - } - - try { - getTransactionCoordinator().explicitJoin(); - } - catch ( TransactionRequiredForJoinException e ) { - throw new TransactionRequiredException( e.getMessage() ); - } - catch ( HibernateException he ) { - throw getExceptionConverter().convert( he ); - } - } - - @Override - public boolean isJoinedToTransaction() { - checkOpen(); - return getTransactionCoordinator().isJoined(); - } - @Override @SuppressWarnings("unchecked") public T unwrap(Class clazz) {