HHH-18444 Remove deprecate Session#refresh methods

This commit is contained in:
Andrea Boriero 2024-07-29 10:49:07 +02:00 committed by Steve Ebersole
parent facd46ffea
commit ec556f0fa5
9 changed files with 10 additions and 86 deletions

View File

@ -791,29 +791,6 @@ public interface Session extends SharedSessionContract, EntityManager {
*/
void refresh(Object object);
/**
* Reread the state of the given managed instance associated with this session
* from the underlying database. This may be useful:
* <ul>
* <li>when a database trigger alters the object state upon insert or update,
* <li>after {@linkplain #createMutationQuery(String) executing} any HQL update
* or delete statement,
* <li>after {@linkplain #createNativeMutationQuery(String) executing} a native
* SQL statement, or
* <li>after inserting a {@link java.sql.Blob} or {@link java.sql.Clob}.
* </ul>
* <p>
* This operation cascades to associated instances if the association is mapped
* with {@link jakarta.persistence.CascadeType#REFRESH}.
*
* @param entityName the name of the entity
* @param object a persistent instance associated with this session
*
* @deprecated use {@link #refresh(Object)}
*/
@Deprecated(since = "6.0")
void refresh(String entityName, Object object);
/**
* Reread the state of the given managed instance from the underlying database,
* obtaining the given {@link LockMode}.
@ -836,19 +813,6 @@ public interface Session extends SharedSessionContract, EntityManager {
*/
void refresh(Object object, LockOptions lockOptions);
/**
* Reread the state of the given managed instance from the underlying database,
* obtaining the given {@link LockMode}.
*
* @param entityName the name of the entity
* @param object a persistent instance associated with this session
* @param lockOptions contains the lock mode to use
*
* @deprecated use {@link #refresh(Object, LockOptions)}
*/
@Deprecated(since = "6.0")
void refresh(String entityName, Object object, LockOptions lockOptions);
/**
* Mark a persistence instance associated with this session for removal from
* the underlying database. Ths operation cascades to associated instances if

View File

@ -972,11 +972,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
delegate.refresh( entity, options );
}
@Override
public void refresh(String entityName, Object object) {
delegate.refresh( entityName, object );
}
@Override
public void refresh(Object object, LockMode lockMode) {
delegate.refresh( object, lockMode );
@ -987,11 +982,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
delegate.refresh( object, lockOptions );
}
@Override
public void refresh(String entityName, Object object, LockOptions lockOptions) {
delegate.refresh( entityName, object, lockOptions );
}
@Override
public LockMode getCurrentLockMode(Object object) {
return delegate.getCurrentLockMode( object );
@ -1197,11 +1187,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
delegate.persistOnFlush( entityName, object, copiedAlready );
}
@Override
public void refresh(String entityName, Object object, RefreshContext refreshedAlready) throws HibernateException {
delegate.refresh( entityName, object, refreshedAlready );
}
@Override
public void removeOrphanBeforeUpdates(String entityName, Object child) {
delegate.removeOrphanBeforeUpdates( entityName, child );

View File

@ -121,12 +121,6 @@ public interface SessionImplementor extends Session, SharedSessionContractImplem
@Deprecated
void persistOnFlush(String entityName, Object object, PersistContext copiedAlready);
/**
* @deprecated OperationalContext should cover this overload I believe
*/
@Deprecated
void refresh(String entityName, Object object, RefreshContext refreshedAlready) throws HibernateException;
/**
* @deprecated OperationalContext should cover this overload I believe
*/

View File

@ -285,12 +285,6 @@ public class SessionLazyDelegator implements Session {
this.lazySession.get().refresh( object );
}
@Override
@Deprecated
public void refresh(String entityName, Object object) {
this.lazySession.get().refresh( entityName, object );
}
@Override
public void refresh(Object object, LockMode lockMode) {
this.lazySession.get().refresh( object, lockMode );
@ -301,12 +295,6 @@ public class SessionLazyDelegator implements Session {
this.lazySession.get().refresh( object, lockOptions );
}
@Override
@Deprecated
public void refresh(String entityName, Object object, LockOptions lockOptions) {
this.lazySession.get().refresh( entityName, object, lockOptions );
}
@Override
public void remove(Object object) {
this.lazySession.get().remove( object );

View File

@ -49,6 +49,11 @@ public class RefreshEvent extends AbstractEvent {
}
this.lockOptions = lockOptions;
}
/**
* @deprecated use {@link #RefreshEvent(Object, LockOptions, EventSource)} instead.
*/
@Deprecated(since = "7.0")
public RefreshEvent(String entityName, Object object, LockOptions lockOptions, EventSource source){
this(object,lockOptions,source);
this.entityName = entityName;

View File

@ -1178,13 +1178,7 @@ public class SessionImpl
@Override
public void refresh(Object object) throws HibernateException {
checkOpen();
fireRefresh( new RefreshEvent( null, object, this ) );
}
@Override @Deprecated
public void refresh(String entityName, Object object) throws HibernateException {
checkOpen();
fireRefresh( new RefreshEvent( entityName, object, this ) );
fireRefresh( new RefreshEvent( object, this ) );
}
@Override
@ -1196,13 +1190,7 @@ public class SessionImpl
@Override
public void refresh(Object object, LockOptions lockOptions) throws HibernateException {
checkOpen();
refresh( null, object, lockOptions );
}
@Override @Deprecated
public void refresh(String entityName, Object object, LockOptions lockOptions) throws HibernateException {
checkOpen();
fireRefresh( new RefreshEvent( entityName, object, lockOptions, this ) );
fireRefresh( new RefreshEvent( object, lockOptions, this ) );
}
@Override

View File

@ -210,8 +210,6 @@ public class LockModeTest extends BaseSessionFactoryFunctionalTest {
checkLockMode( a, LockMode.PESSIMISTIC_READ, session );
session.refresh( a );
checkLockMode( a, LockMode.PESSIMISTIC_READ, session );
session.refresh( A.class.getName(), a );
checkLockMode( a, LockMode.PESSIMISTIC_READ, session );
session.refresh( a, Collections.emptyMap() );
checkLockMode( a, LockMode.PESSIMISTIC_READ, session );
session.refresh( a, null, Collections.emptyMap() );

View File

@ -46,7 +46,7 @@ public class RefreshUsingEntityNameTest {
public void testRefreshUsingEntityName(SessionFactoryScope scope) {
scope.inSession(
session ->
session.refresh( "CustomName", customer )
session.refresh( customer )
);
}
}

View File

@ -135,6 +135,8 @@ All such cases though are already controllable by the application.
The effect can also often be mitigated using Hibernate's bytecode-based laziness (possibly combined with `@ConcreteProxy`).
* Removed `org.hibernate.Session#refresh(String entityName, Object object)` in favor of `org.hibernate.Session#refresh(Object object)`
* Removed `org.hibernate.Session#refresh(String entityName, Object object, LockOptions lockOptions)` in favor of `org.hibernate.Session#refresh(Object object, LockOptions lockOptions)`
[[flush-persist]]
== Session flush and persist