|
37 | 37 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.PREVIOUS_STATUS; |
38 | 38 | import static org.hibernate.engine.internal.EntityEntryImpl.EnumState.STATUS; |
39 | 39 | import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity; |
40 | | -import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; |
| 40 | +import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptableOrNull; |
41 | 41 | 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 | 42 | import static org.hibernate.engine.internal.ManagedTypeHelper.isSelfDirtinessTracker; |
45 | 43 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfManagedEntity; |
46 | 44 | import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker; |
|
52 | 50 | import static org.hibernate.engine.spi.Status.SAVING; |
53 | 51 | import static org.hibernate.internal.util.StringHelper.nullIfEmpty; |
54 | 52 | import static org.hibernate.pretty.MessageHelper.infoString; |
55 | | -import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; |
56 | 53 |
|
57 | 54 | /** |
58 | 55 | * A base implementation of {@link EntityEntry}. |
@@ -385,43 +382,31 @@ private boolean isUnequivocallyNonDirty(Object entity) { |
385 | 382 | } |
386 | 383 |
|
387 | 384 | private boolean isNonDirtyViaCustomStrategy(Object entity) { |
388 | | - if ( isPersistentAttributeInterceptable( entity ) ) { |
389 | | - if ( asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor() |
390 | | - instanceof EnhancementAsProxyLazinessInterceptor ) { |
| 385 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 386 | + if ( interceptable != null ) { |
| 387 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor |
| 388 | + && !interceptor.isInitialized() ) { |
391 | 389 | // we never have to check an uninitialized proxy |
392 | 390 | return true; |
393 | 391 | } |
394 | 392 | } |
395 | | - |
396 | 393 | final var session = (SessionImplementor) getPersistenceContext().getSession(); |
397 | 394 | final var customEntityDirtinessStrategy = session.getFactory().getCustomEntityDirtinessStrategy(); |
398 | 395 | return customEntityDirtinessStrategy.canDirtyCheck( entity, persister, session ) |
399 | 396 | && !customEntityDirtinessStrategy.isDirty( entity, persister, session ); |
400 | 397 | } |
401 | 398 |
|
402 | 399 | 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; |
| 400 | + final var interceptable = asPersistentAttributeInterceptableOrNull( entity ); |
| 401 | + if ( interceptable != null ) { |
| 402 | + if ( interceptable.$$_hibernate_getInterceptor() instanceof EnhancementAsProxyLazinessInterceptor interceptor ) { |
| 403 | + return !interceptor.hasWrittenFieldNames(); |
411 | 404 | } |
412 | 405 | } |
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(); |
| 406 | + return !persister.hasCollections() |
| 407 | + && !persister.hasMutableProperties() |
| 408 | + && asManagedEntity( entity ).$$_hibernate_useTracker() |
| 409 | + && !asSelfDirtinessTracker( entity ).$$_hibernate_hasDirtyAttributes(); |
425 | 410 | } |
426 | 411 |
|
427 | 412 | @Override |
|
0 commit comments