diff --git a/hibernate-core/src/main/java/org/hibernate/Session.java b/hibernate-core/src/main/java/org/hibernate/Session.java index 191539ab0f..467bee9581 100644 --- a/hibernate-core/src/main/java/org/hibernate/Session.java +++ b/hibernate-core/src/main/java/org/hibernate/Session.java @@ -22,7 +22,6 @@ import jakarta.persistence.EntityGraph; import jakarta.persistence.EntityManager; import jakarta.persistence.FlushModeType; import jakarta.persistence.LockModeType; -import jakarta.persistence.PessimisticLockScope; import jakarta.persistence.TypedQueryReference; import jakarta.persistence.criteria.CriteriaDelete; import jakarta.persistence.criteria.CriteriaQuery; @@ -635,31 +634,6 @@ public interface Session extends SharedSessionContract, EntityManager { @Deprecated(since = "6.2") void lock(String entityName, Object object, LockMode lockMode); - /** - * Build a new {@linkplain LockRequest lock request} that specifies: - * - *

- * Timeout and scope are ignored if the specified {@code LockMode} represents - * a flavor of {@linkplain LockMode#OPTIMISTIC optimistic} locking. - *

- * Call {@link LockRequest#lock(Object)} to actually obtain the requested lock - * on a managed entity instance. - * - * @param lockOptions contains the lock level - * - * @return a {@link LockRequest} that can be used to lock any given object. - * - * @deprecated use {@link #lock(Object, LockOptions)} - */ - @Deprecated(since = "6.2") - LockRequest buildLockRequest(LockOptions lockOptions); - /** * Reread the state of the given managed instance associated with this session * from the underlying database. This may be useful: @@ -1157,125 +1131,6 @@ public interface Session extends SharedSessionContract, EntityManager { */ SharedSessionBuilder sessionWithOptions(); - /** - * A set of {@linkplain LockOptions locking options} attached - * to the session. - * - * @deprecated simply construct a {@link LockOptions} and pass - * it to {@link #lock(Object, LockOptions)}. - */ - @Deprecated(since = "6.2") - interface LockRequest { - /** - * A timeout value indicating that the database should not - * wait at all to acquire a pessimistic lock which is not - * immediately available. This has the same effect as - * {@link LockMode#UPGRADE_NOWAIT}. - */ - int PESSIMISTIC_NO_WAIT = LockOptions.NO_WAIT; - - /** - * A timeout value indicating that attempting to acquire - * that there is no timeout for the lock acquisition. - */ - int PESSIMISTIC_WAIT_FOREVER = LockOptions.WAIT_FOREVER; - - /** - * Get the lock mode. - * - * @return the lock mode. - */ - LockMode getLockMode(); - - /** - * Specify the {@link LockMode} to be used. The default is {@link LockMode#NONE}. - * - * @param lockMode the lock mode to use for this request - * - * @return this {@code LockRequest} instance for operation chaining. - */ - LockRequest setLockMode(LockMode lockMode); - - /** - * Get the timeout setting. - * - * @return timeout in milliseconds, -1 for indefinite wait and 0 for no wait. - */ - int getTimeOut(); - - /** - * Specify the pessimistic lock timeout. The default pessimistic lock - * behavior is to wait forever for the lock. Lock timeout support is - * not available in every {@link org.hibernate.dialect.Dialect dialect} - * of SQL. - * - * @param timeout is time in milliseconds to wait for lock. - * -1 means wait forever and 0 means no wait. - * - * @return this {@code LockRequest} instance for operation chaining. - */ - LockRequest setTimeOut(int timeout); - - /** - * Check if locking extends to owned collections and associated entities. - * - * @return true if locking will be extended to owned collections and associated entities - * - * @deprecated use {@link #getLockScope()} - */ - @Deprecated(since = "6.2") - boolean getScope(); - - /** - * Obtain the {@link PessimisticLockScope}, which determines if locking - * extends to owned collections and associated entities. - */ - default PessimisticLockScope getLockScope() { - return getScope() ? PessimisticLockScope.EXTENDED : PessimisticLockScope.NORMAL; - } - - /** - * Specify whether the {@link LockMode} should extend to owned collections - * and associated entities. An association must be mapped with - * {@link org.hibernate.annotations.CascadeType#LOCK} for this setting to - * have any effect. - * - * @param scope {@code true} to cascade locks; {@code false} to not. - * - * @return {@code this}, for method chaining - * - * @deprecated use {@link #setLockScope(PessimisticLockScope)} - */ - @Deprecated(since = "6.2") - LockRequest setScope(boolean scope); - - /** - * Set the {@link PessimisticLockScope}, which determines if locking - * extends to owned collections and associated entities. - */ - default LockRequest setLockScope(PessimisticLockScope scope) { - return setScope( scope == PessimisticLockScope.EXTENDED ); - } - - /** - * Perform the requested locking. - * - * @param entityName the name of the entity to lock - * @param object the instance of the entity to lock - * - * @deprecated use {@link #lock(Object)} - */ - @Deprecated(since = "6.2") - void lock(String entityName, Object object); - - /** - * Perform the requested locking. - * - * @param object the instance of the entity to lock - */ - void lock(Object object); - } - /** * Add one or more listeners to the Session * 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 b0a301c16a..111cdf1d20 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 @@ -910,11 +910,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { delegate.lock( object, lockOptions ); } - @Override @Deprecated - public LockRequest buildLockRequest(LockOptions lockOptions) { - return delegate.buildLockRequest( lockOptions ); - } - @Override public void refresh(Object object) { delegate.refresh( object ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java index a68e3bcb53..540781b88f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionLazyDelegator.java @@ -238,12 +238,6 @@ public class SessionLazyDelegator implements Session { this.lazySession.get().lock( object, lockOptions ); } - @Override - @Deprecated - public LockRequest buildLockRequest(LockOptions lockOptions) { - return this.lazySession.get().buildLockRequest( lockOptions ); - } - @Override public void refresh(Object object) { this.lazySession.get().refresh( object ); 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 2ecd75dd17..72c7883682 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -652,20 +652,11 @@ public class SessionImpl fireLock( new LockEvent( entityName, object, lockMode, this ) ); } - @Override @Deprecated - public LockRequest buildLockRequest(LockOptions lockOptions) { - return new LockRequestImpl( lockOptions ); - } - @Override public void lock(Object object, LockMode lockMode) throws HibernateException { fireLock( new LockEvent( object, lockMode, this ) ); } - private void fireLock(String entityName, Object object, LockOptions options) { - fireLock( new LockEvent( entityName, object, options, this ) ); - } - private void fireLock(Object object, LockOptions options) { fireLock( new LockEvent( object, options, this ) ); } @@ -2164,59 +2155,6 @@ public class SessionImpl } } - @Deprecated - private class LockRequestImpl implements LockRequest { - private final LockOptions lockOptions; - - private LockRequestImpl(LockOptions lockOptions) { - this.lockOptions = new LockOptions(); - LockOptions.copy( lockOptions, this.lockOptions ); - } - - @Override - public LockMode getLockMode() { - return lockOptions.getLockMode(); - } - - @Override - public LockRequest setLockMode(LockMode lockMode) { - lockOptions.setLockMode( lockMode ); - return this; - } - - @Override - public int getTimeOut() { - return lockOptions.getTimeOut(); - } - - @Override - public LockRequest setTimeOut(int timeout) { - lockOptions.setTimeOut( timeout ); - return this; - } - - @Override @Deprecated @SuppressWarnings("deprecation") - public boolean getScope() { - return lockOptions.getScope(); - } - - @Override @Deprecated @SuppressWarnings("deprecation") - public LockRequest setScope(boolean scope) { - lockOptions.setScope( scope ); - return this; - } - - @Override @Deprecated @SuppressWarnings("deprecation") - public void lock(String entityName, Object object) throws HibernateException { - fireLock( entityName, object, lockOptions ); - } - - @Override - public void lock(Object object) throws HibernateException { - fireLock( object, lockOptions ); - } - } - @Override protected void addSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) { transactionObserver = new TransactionObserver() { @@ -2586,7 +2524,7 @@ public class SessionImpl final LockOptions lockOptions = buildLockOptions( lockModeType, properties ); try { - buildLockRequest( lockOptions ).lock( entity ); + fireLock( entity, lockOptions ); } catch (RuntimeException e) { throw getExceptionConverter().convert( e, lockOptions ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectTest.java index a8feea0f14..e5d0258a7a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectTest.java @@ -368,7 +368,7 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase { long start = System.currentTimeMillis(); thread.start(); try { - s2.buildLockRequest( opt ).lock( kit2 ); + s2.lock( kit2, opt ); } catch ( PessimisticEntityLockException e ) { assertTrue( e.getCause() instanceof LockTimeoutException ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/MutableNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/MutableNaturalIdTest.java index 37ede30092..29778e508c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/MutableNaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/MutableNaturalIdTest.java @@ -148,7 +148,7 @@ public class MutableNaturalIdTest { scope.inTransaction( (session) -> { try { - session.buildLockRequest( LockOptions.NONE ).lock( created ); + session.lock( created, LockOptions.NONE ); name.set( created, "Gavin" ); final User loaded = session diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/cached/CachedMutableNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/cached/CachedMutableNaturalIdTest.java index 28e367b912..fb9d3afb58 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/cached/CachedMutableNaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/mutable/cached/CachedMutableNaturalIdTest.java @@ -295,7 +295,7 @@ public abstract class CachedMutableNaturalIdTest { scope.inTransaction( (session) -> { // HHH-7513 failure during reattachment - session.buildLockRequest( LockOptions.NONE ).lock( created ); + session.lock( created, LockOptions.NONE ); session.remove( created.assA ); session.remove( created ); } 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 0e732a131a..0dd3f6592f 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 @@ -593,7 +593,7 @@ public class ProxyTest extends BaseCoreFunctionalTestCase { dp = s.load( DataPoint.class, dp.getId()); assertFalse( Hibernate.isInitialized( dp ) ); - s.buildLockRequest( LockOptions.UPGRADE ).lock( dp ); + s.lock( dp, LockOptions.UPGRADE ); assertSame( LockOptions.UPGRADE.getLockMode(), s.getCurrentLockMode( dp ) ); s.remove( dp );