| DefaultAutoFlushEventListener#onAutoFlush, the method responsible for implementing automatic flushes, goes like this:
if ( flushMightBeNeeded( source ) ) {
< add the flush actions to the action queue >
if ( flushIsReallyNeeded( event, source ) ) { < execute the action queue >
< clear the action queue >
}
else {
< remove from the action queue the actions we just added >
}
event.setFlushRequired( flushIsReallyNeeded( event, source ) ); }
The second call to flushIsReallyNeeded inspects an action queue that is either empty, or devoid of any action related to the flush, so it will often (always?) return false. This is a problem for other implementors of AutoFlushEvent listeners, because we cannot know whether a flush actually occurred or not. In Hibernate Search, it is problematic for HSEARCH-3360 Pull Request Sent in particular (see this comment). I suspect this bug might cause a few other bugs in ORM, too, because isFlushRequired is used as the return value of org.hibernate.internal.SessionImpl#autoFlushIfRequired, which in turn is used in org.hibernate.internal.SessionImpl#getFilterQueryPlan to handle some edge case. I think this edge case handling code is currently dead code. |