diff --git a/hibernate-core/src/main/java/org/hibernate/Session.java b/hibernate-core/src/main/java/org/hibernate/Session.java index 7e65c8f5d4..0001ee22b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/Session.java +++ b/hibernate-core/src/main/java/org/hibernate/Session.java @@ -7,7 +7,6 @@ package org.hibernate; import java.io.Closeable; -import java.sql.Connection; import java.util.List; import jakarta.persistence.EntityGraph; import jakarta.persistence.EntityManager; @@ -962,31 +961,6 @@ public interface Session extends SharedSessionContract, EntityManager, AutoClose return (List) getSessionFactory().findEntityGraphsByType( entityClass ); } - /** - * Disconnect the session from its underlying JDBC connection. This is intended for use in cases where the - * application has supplied the JDBC connection to the session and which require long-sessions (aka, conversations). - *

- * It is considered an error to call this method on a session which was not opened by supplying the JDBC connection - * and an exception will be thrown. - *

- * For non-user-supplied scenarios, normal transaction management already handles disconnection and reconnection - * automatically. - * - * @return the application-supplied connection or {@code null} - * - * @see #reconnect(Connection) - */ - Connection disconnect(); - - /** - * Reconnect to the given JDBC connection. - * - * @param connection a JDBC connection - * - * @see #disconnect() - */ - void reconnect(Connection connection); - /** * Is a particular fetch profile enabled on this session? * diff --git a/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java b/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java index fa0fe3f6ac..4feebd4a94 100644 --- a/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java +++ b/hibernate-core/src/main/java/org/hibernate/context/internal/ThreadLocalSessionContext.java @@ -335,13 +335,10 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext { || "setHibernateFlushMode".equals( methodName ) || "getFactory".equals( methodName ) || "getSessionFactory".equals( methodName ) + || "getJdbcCoordinator".equals( methodName ) || "getTenantIdentifier".equals( methodName ) ) { LOG.tracef( "Allowing invocation [%s] to proceed to real (non-transacted) session", methodName ); } - else if ( "reconnect".equals( methodName ) || "disconnect".equals( methodName ) ) { - // allow these (deprecated) methods to pass through - LOG.tracef( "Allowing invocation [%s] to proceed to real (non-transacted) session - deprecated methods", methodName ); - } else { throw new HibernateException( "Calling method '" + methodName + "' is not valid without an active transaction (Current status: " + realSession.getTransaction().getStatus() + ")" ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index f354b87c50..0a5f3678fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -987,16 +987,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return delegate.doReturningWork( work ); } - @Override - public Connection disconnect() { - return delegate.disconnect(); - } - - @Override - public void reconnect(Connection connection) { - delegate.reconnect( connection ); - } - @Override public boolean isFetchProfileEnabled(String name) throws UnknownProfileException { return delegate.isFetchProfileEnabled( name ); 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 f8e00c6c24..96f9334212 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -14,7 +14,6 @@ import java.io.Reader; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; -import java.sql.Connection; import java.sql.NClob; import java.sql.SQLException; import java.util.Collections; @@ -487,21 +486,6 @@ public class SessionImpl closeWithoutOpenChecks(); } - @Override - public Connection disconnect() throws HibernateException { - checkOpen(); - log.debug( "Disconnecting session" ); - return getJdbcCoordinator().getLogicalConnection().manualDisconnect(); - } - - @Override - public void reconnect(Connection conn) throws HibernateException { - checkOpen(); - log.debug( "Reconnecting session" ); - checkTransactionSynchStatus(); - getJdbcCoordinator().getLogicalConnection().manualReconnect( conn ); - } - @Override public void setAutoClear(boolean enabled) { checkOpenOrWaitingForAutoClose(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index 20156f1c69..ba0e980b46 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -6,7 +6,6 @@ */ package org.hibernate.internal; -import java.sql.Connection; import java.util.Set; import org.hibernate.CacheMode; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/connections/ConnectionManagementTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/connections/ConnectionManagementTestCase.java index 952fd5b279..059dfe32de 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/connections/ConnectionManagementTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/connections/ConnectionManagementTestCase.java @@ -8,6 +8,7 @@ package org.hibernate.orm.test.connections; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.util.SerializationHelper; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; @@ -91,7 +92,7 @@ public abstract class ConnectionManagementTestCase extends BaseNonConfigCoreFunc } protected void disconnect(Session session) throws Throwable { - session.disconnect(); + ((SessionImplementor)session).getJdbcCoordinator().getLogicalConnection().manualDisconnect(); } /** diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/connections/SuppliedConnectionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/connections/SuppliedConnectionTest.java index 52ab9caaf6..f237854dfe 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/connections/SuppliedConnectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/connections/SuppliedConnectionTest.java @@ -17,6 +17,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; import org.hibernate.service.spi.Stoppable; import org.hibernate.tool.schema.internal.SchemaCreatorImpl; @@ -68,7 +69,7 @@ public class SuppliedConnectionTest extends ConnectionManagementTestCase { @Override protected void reconnect(Session session) { - session.reconnect( connectionUnderTest ); + ((SessionImplementor)session).getJdbcCoordinator().getLogicalConnection().manualReconnect( connectionUnderTest ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerFactorySerializationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerFactorySerializationTest.java index 607e72abc6..36ae80f3a6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerFactorySerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerFactorySerializationTest.java @@ -17,6 +17,7 @@ import jakarta.persistence.EntityManagerFactory; import org.hibernate.Session; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.orm.test.jpa.Cat; import org.hibernate.orm.test.jpa.Distributor; import org.hibernate.orm.test.jpa.Item; @@ -77,7 +78,7 @@ public class EntityManagerFactorySerializationTest { //em.getTransaction().commit(); //fake the in container work - em.unwrap( Session.class ).disconnect(); + em.unwrap( SessionImplementor.class ).getJdbcCoordinator().getLogicalConnection().manualDisconnect(); stream = new ByteArrayOutputStream(); out = new ObjectOutputStream( stream ); out.writeObject( em ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerSerializationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerSerializationTest.java index 28b6a5f053..11edc1912e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerSerializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ejb3configuration/EntityManagerSerializationTest.java @@ -14,6 +14,7 @@ import java.io.ObjectOutputStream; import java.util.Date; import org.hibernate.Session; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.orm.test.jpa.Cat; import org.hibernate.orm.test.jpa.Distributor; import org.hibernate.orm.test.jpa.Item; @@ -63,7 +64,7 @@ public class EntityManagerSerializationTest { item.setDescr( "Paris-Bruxelles" ); //fake the in container work - em.unwrap( Session.class ).disconnect(); + em.unwrap( SessionImplementor.class ).getJdbcCoordinator().getLogicalConnection().manualDisconnect(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream( stream ); out.writeObject( em ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/ProxyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/ProxyTest.java index ba65ca6197..16a3781059 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/ProxyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/proxy/ProxyTest.java @@ -19,6 +19,7 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.SessionImpl; import org.hibernate.internal.util.SerializationHelper; import org.hibernate.proxy.HibernateProxy; @@ -180,7 +181,7 @@ public class ProxyTest extends BaseCoreFunctionalTestCase { assertFalse( Hibernate.isInitialized(none) ); t.commit(); - s.disconnect(); + s.unwrap( SessionImplementor.class ).getJdbcCoordinator().getLogicalConnection().manualDisconnect(); Object[] holder = new Object[] { s, dp, none };