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 ;
@@ -385,9 +383,17 @@ 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 () ) {
390
+ // we never have to check an uninitialized proxy
391
+ return true ;
392
+ }
393
+ }
394
+ else {
395
+ final var lazyInitializer = extractLazyInitializer ( entity );
396
+ if ( lazyInitializer != null && lazyInitializer .isUninitialized () ) {
391
397
// we never have to check an uninitialized proxy
392
398
return true ;
393
399
}
@@ -400,28 +406,24 @@ private boolean isNonDirtyViaCustomStrategy(Object entity) {
400
406
}
401
407
402
408
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 ();
409
+ final var interceptable = asPersistentAttributeInterceptableOrNull ( entity );
410
+ if ( interceptable != null ) {
411
+ if ( interceptable .$$_hibernate_getInterceptor () instanceof EnhancementAsProxyLazinessInterceptor interceptor ) {
412
+ return !interceptor .hasWrittenFieldNames ();
408
413
}
409
- else {
410
- uninitializedProxy = false ;
411
- }
412
- }
413
- else if ( isHibernateProxy ( entity ) ) {
414
- uninitializedProxy = extractLazyInitializer ( entity ).isUninitialized ();
415
414
}
416
415
else {
417
- uninitializedProxy = false ;
416
+ final var lazyInitializer = extractLazyInitializer ( entity );
417
+ if ( lazyInitializer != null && lazyInitializer .isUninitialized () ) {
418
+ // we never have to check an uninitialized proxy
419
+ return true ;
420
+ }
418
421
}
419
422
// 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 ();
423
+ return !persister .hasCollections ()
424
+ && !persister .hasMutableProperties ()
425
+ && asManagedEntity ( entity ).$$_hibernate_useTracker ()
426
+ && !asSelfDirtinessTracker ( entity ).$$_hibernate_hasDirtyAttributes ();
425
427
}
426
428
427
429
@ Override
0 commit comments