|
26 | 26 | import org.hibernate.engine.spi.Status;
|
27 | 27 | import org.hibernate.internal.util.ImmutableBitSet;
|
28 | 28 | import org.hibernate.persister.entity.EntityPersister;
|
| 29 | +import org.hibernate.proxy.HibernateProxy; |
29 | 30 | import org.hibernate.type.TypeHelper;
|
30 | 31 |
|
31 | 32 | import org.checkerframework.checker.nullness.qual.Nullable;
|
|
37 | 38 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.PREVIOUS_STATUS;
|
38 | 39 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.STATUS;
|
39 | 40 | import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity;
|
40 |
| -import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; |
| 41 | +import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptableOrNull; |
41 | 42 | import static org.hibernate.engine.internal.ManagedTypeHelper.asSelfDirtinessTracker;
|
42 |
| -import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy; |
43 |
| -import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; |
44 | 43 | import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker;
|
45 | 44 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfManagedEntity;
|
46 | 45 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker;
|
|
52 | 51 | import static org.hibernate.engine.spi.Status.SAVING;
|
53 | 52 | import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
54 | 53 | import static org.hibernate.pretty.MessageHelper.infoString;
|
55 |
| -import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; |
56 | 54 |
|
57 | 55 | /**
|
58 | 56 | * A base implementation of {@link EntityEntry}.
|
@@ -385,43 +383,31 @@ private boolean isUnequivocallyNonDirty(Object entity) {
|
385 | 383 | }
|
386 | 384 |
|
387 | 385 | private boolean isNonDirtyViaCustomStrategy(Object entity) {
|
388 |
| - if ( isPersistentAttributeInterceptable( entity ) ) { |
389 |
| - if ( asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor() |
390 |
| - instanceof EnhancementAsProxyLazinessInterceptor ) { |
| 386 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 387 | + if ( interceptable != null ) { |
| 388 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor |
| 389 | + && !interceptor.isInitialized() ) { |
391 | 390 | // we never have to check an uninitialized proxy
|
392 | 391 | return true;
|
393 | 392 | }
|
394 | 393 | }
|
395 |
| - |
396 | 394 | final var session = (SessionImplementor) getPersistenceContext().getSession();
|
397 | 395 | final var customEntityDirtinessStrategy = session.getFactory().getCustomEntityDirtinessStrategy();
|
398 | 396 | return customEntityDirtinessStrategy.canDirtyCheck( entity, persister, session )
|
399 | 397 | && !customEntityDirtinessStrategy.isDirty( entity, persister, session );
|
400 | 398 | }
|
401 | 399 |
|
402 | 400 | private boolean isNonDirtyViaTracker(Object entity) {
|
403 |
| - final boolean uninitializedProxy; |
404 |
| - if ( isPersistentAttributeInterceptable( entity ) ) { |
405 |
| - if ( asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor() |
406 |
| - instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) { |
407 |
| - return !lazinessInterceptor.hasWrittenFieldNames(); |
408 |
| - } |
409 |
| - else { |
410 |
| - uninitializedProxy = false; |
| 401 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 402 | + if ( interceptable != null ) { |
| 403 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor ) { |
| 404 | + return !interceptor.hasWrittenFieldNames(); |
411 | 405 | }
|
412 | 406 | }
|
413 |
| - else if ( isHibernateProxy( entity ) ) { |
414 |
| - uninitializedProxy = extractLazyInitializer( entity ).isUninitialized(); |
415 |
| - } |
416 |
| - else { |
417 |
| - uninitializedProxy = false; |
418 |
| - } |
419 |
| - // we never have to check an uninitialized proxy |
420 |
| - return uninitializedProxy |
421 |
| - || !persister.hasCollections() |
422 |
| - && !persister.hasMutableProperties() |
423 |
| - && !asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes() |
424 |
| - && asManagedEntity( entity ).$$_hibernate_useTracker(); |
| 407 | + return !persister.hasCollections() |
| 408 | + && !persister.hasMutableProperties() |
| 409 | + && asManagedEntity( entity ).$$_hibernate_useTracker() |
| 410 | + && !asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes(); |
425 | 411 | }
|
426 | 412 |
|
427 | 413 | @Override
|
|
0 commit comments