4
4
*/
5
5
package org .hibernate .event .internal ;
6
6
7
+ import org .hibernate .AssertionFailure ;
7
8
import org .hibernate .HibernateException ;
8
9
import org .hibernate .collection .spi .PersistentCollection ;
9
10
import org .hibernate .engine .spi .EntityEntry ;
@@ -42,11 +43,7 @@ public void onDirtyCheck(DirtyCheckEvent event) throws HibernateException {
42
43
final var holdersByKey = persistenceContext .getEntityHoldersByKey ();
43
44
if ( holdersByKey != null ) {
44
45
for ( var entry : holdersByKey .entrySet () ) {
45
- final EntityHolder holder = entry .getValue ();
46
- final EntityEntry entityEntry = holder .getEntityEntry ();
47
- final Status status = entityEntry .getStatus ();
48
- if ( status != Status .MANAGED && status != Status .GONE
49
- || isEntityDirty ( holder .getManagedObject (), holder .getDescriptor (), entityEntry , session ) ) {
46
+ if ( isEntityDirty ( entry .getValue (), session ) ) {
50
47
event .setDirty ( true );
51
48
return ;
52
49
}
@@ -63,7 +60,18 @@ public void onDirtyCheck(DirtyCheckEvent event) throws HibernateException {
63
60
}
64
61
}
65
62
66
- private static boolean isEntityDirty (
63
+ private static boolean isEntityDirty (EntityHolder holder , EventSource session ) {
64
+ final EntityEntry entityEntry = holder .getEntityEntry ();
65
+ final Status status = entityEntry .getStatus ();
66
+ return switch ( status ) {
67
+ case GONE , READ_ONLY -> false ;
68
+ case DELETED -> true ;
69
+ case MANAGED -> isManagedEntityDirty ( holder .getManagedObject (), holder .getDescriptor (), entityEntry , session );
70
+ case SAVING , LOADING -> throw new AssertionFailure ( "Unexpected status: " + status );
71
+ };
72
+ }
73
+
74
+ private static boolean isManagedEntityDirty (
67
75
Object entity , EntityPersister descriptor , EntityEntry entityEntry , EventSource session ) {
68
76
if ( entityEntry .requiresDirtyCheck ( entity ) ) { // takes into account CustomEntityDirtinessStrategy
69
77
final Object [] propertyValues =
0 commit comments