44 */
55package org .hibernate .event .internal ;
66
7+ import org .hibernate .AssertionFailure ;
78import org .hibernate .HibernateException ;
89import org .hibernate .collection .spi .PersistentCollection ;
910import org .hibernate .engine .spi .EntityEntry ;
@@ -42,11 +43,7 @@ public void onDirtyCheck(DirtyCheckEvent event) throws HibernateException {
4243 final var holdersByKey = persistenceContext .getEntityHoldersByKey ();
4344 if ( holdersByKey != null ) {
4445 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 ) ) {
5047 event .setDirty ( true );
5148 return ;
5249 }
@@ -63,7 +60,18 @@ public void onDirtyCheck(DirtyCheckEvent event) throws HibernateException {
6360 }
6461 }
6562
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 (
6775 Object entity , EntityPersister descriptor , EntityEntry entityEntry , EventSource session ) {
6876 if ( entityEntry .requiresDirtyCheck ( entity ) ) { // takes into account CustomEntityDirtinessStrategy
6977 final Object [] propertyValues =
0 commit comments