We found flushes to still be slow even when using a CustomEntityDirtinessStrategy and even if no changes need to be flushed. In these cases it seems Hibernate still reads every field of every ( ? ) entity in the session to verify possible 1:1 orphan removals in Cascade.cascade() here Cascade.java#L183. In most cases the value will simply be discarded, because the type check isLogicalOneToOne() will be false anyway. It looks as if this cost could easily be avoided by moving
if ( isLogicalOneToOne( type ) )
from inside cascadeLogicalOneToOneOrphanRemoval() to before/around the call to cascadeLogicalOneToOneOrphanRemoval() for both callers, which would avoid the eager reading of all fields for every flush. Example stack of the unnecessary field reading:
|