misc cleanups

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-08-31 19:09:13 +02:00
parent 09fa8ef76a
commit f7db3f0005
4 changed files with 16 additions and 16 deletions

View File

@ -772,10 +772,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
*/ */
private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) { private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) {
if ( li.getSession() != this.getSession() ) { if ( li.getSession() != this.getSession() ) {
final EntityPersister persister = session.getFactory() final EntityPersister persister =
.getRuntimeMetamodels() session.getFactory().getMappingMetamodel()
.getMappingMetamodel() .getEntityDescriptor( li.getEntityName() );
.getEntityDescriptor( li.getEntityName() );
final EntityKey key = session.generateEntityKey( li.getInternalIdentifier(), persister ); final EntityKey key = session.generateEntityKey( li.getInternalIdentifier(), persister );
// any earlier proxy takes precedence // any earlier proxy takes precedence
final Map<EntityKey, EntityHolderImpl> entityHolderMap = getOrInitializeEntitiesByKey(); final Map<EntityKey, EntityHolderImpl> entityHolderMap = getOrInitializeEntitiesByKey();

View File

@ -57,6 +57,7 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy;
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker; import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker;
import static org.hibernate.event.internal.EntityState.getEntityState; import static org.hibernate.event.internal.EntityState.getEntityState;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
/** /**
* Defines the default copy event listener used by hibernate for copying entities * Defines the default copy event listener used by hibernate for copying entities
@ -111,7 +112,7 @@ public class DefaultMergeEventListener
// NOTE : `original` is the value being merged // NOTE : `original` is the value being merged
if ( original != null ) { if ( original != null ) {
final EventSource source = event.getSession(); final EventSource source = event.getSession();
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( original ); final LazyInitializer lazyInitializer = extractLazyInitializer( original );
if ( lazyInitializer != null ) { if ( lazyInitializer != null ) {
if ( lazyInitializer.isUninitialized() ) { if ( lazyInitializer.isUninitialized() ) {
LOG.trace( "Ignoring uninitialized proxy" ); LOG.trace( "Ignoring uninitialized proxy" );
@ -122,9 +123,11 @@ public class DefaultMergeEventListener
} }
} }
else if ( isPersistentAttributeInterceptable( original ) ) { else if ( isPersistentAttributeInterceptable( original ) ) {
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( original ).$$_hibernate_getInterceptor(); final PersistentAttributeInterceptor interceptor =
asPersistentAttributeInterceptable( original ).$$_hibernate_getInterceptor();
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) { if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) interceptor; final EnhancementAsProxyLazinessInterceptor proxyInterceptor =
(EnhancementAsProxyLazinessInterceptor) interceptor;
LOG.trace( "Ignoring uninitialized enhanced-proxy" ); LOG.trace( "Ignoring uninitialized enhanced-proxy" );
event.setResult( source.load( proxyInterceptor.getEntityName(), proxyInterceptor.getIdentifier() ) ); event.setResult( source.load( proxyInterceptor.getEntityName(), proxyInterceptor.getIdentifier() ) );
} }

View File

@ -864,8 +864,8 @@ public class SessionImpl
@Override @Override
public void removeOrphanBeforeUpdates(String entityName, Object child) { public void removeOrphanBeforeUpdates(String entityName, Object child) {
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task // TODO: The removeOrphan concept is a temporary "hack" for HHH-6484.
// ordering is improved. // This should be removed once action/task ordering is improved.
final boolean traceEnabled = log.isTraceEnabled(); final boolean traceEnabled = log.isTraceEnabled();
if ( traceEnabled ) { if ( traceEnabled ) {
logRemoveOrphanBeforeUpdates( "begin", entityName, child ); logRemoveOrphanBeforeUpdates( "begin", entityName, child );

View File

@ -52,17 +52,16 @@ public class LoaderHelper {
final LockMode requestedLockMode = lockOptions.getLockMode(); final LockMode requestedLockMode = lockOptions.getLockMode();
if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) { if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
// Request is for a more restrictive lock than the lock already held // Request is for a more restrictive lock than the lock already held
final EntityPersister persister = entry.getPersister();
if ( entry.getStatus().isDeletedOrGone()) { if ( entry.getStatus().isDeletedOrGone()) {
throw new ObjectDeletedException( throw new ObjectDeletedException(
"attempted to lock a deleted instance", "attempted to lock a deleted instance",
entry.getId(), entry.getId(),
entry.getPersister().getEntityName() persister.getEntityName()
); );
} }
final EntityPersister persister = entry.getPersister();
if ( LoaderLogging.LOADER_LOGGER.isTraceEnabled() ) { if ( LoaderLogging.LOADER_LOGGER.isTraceEnabled() ) {
LoaderLogging.LOADER_LOGGER.tracef( LoaderLogging.LOADER_LOGGER.tracef(
"Locking `%s( %s )` in `%s` lock-mode", "Locking `%s( %s )` in `%s` lock-mode",
@ -77,7 +76,7 @@ public class LoaderHelper {
Object ck = null; Object ck = null;
try { try {
if ( cachingEnabled ) { if ( cachingEnabled ) {
EntityDataAccess cache = persister.getCacheAccessStrategy(); final EntityDataAccess cache = persister.getCacheAccessStrategy();
ck = cache.generateCacheKey( entry.getId(), persister, session.getFactory(), session.getTenantIdentifier() ); ck = cache.generateCacheKey( entry.getId(), persister, session.getFactory(), session.getTenantIdentifier() );
lock = cache.lockItem( session, ck, entry.getVersion() ); lock = cache.lockItem( session, ck, entry.getVersion() );
} }
@ -99,9 +98,8 @@ public class LoaderHelper {
if ( persister.isVersioned() && requestedLockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT ) { if ( persister.isVersioned() && requestedLockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT ) {
// todo : should we check the current isolation mode explicitly? // todo : should we check the current isolation mode explicitly?
Object nextVersion = persister.forceVersionIncrement( final Object nextVersion =
entry.getId(), entry.getVersion(), false, session persister.forceVersionIncrement( entry.getId(), entry.getVersion(), false, session );
);
entry.forceLocked( object, nextVersion ); entry.forceLocked( object, nextVersion );
} }
else { else {