AutoFlushEvent#isFlushRequired is always false

Description

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 ) ) { // inspects the action queue to find relevant changes < execute the action queue > < clear the action queue > } else { < remove from the action queue the actions we just added > } event.setFlushRequired( flushIsReallyNeeded( event, source ) ); // inspects the action queue to find relevant changes }

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 https://hibernate.atlassian.net/browse/HSEARCH-3360#icft=HSEARCH-3360 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.

Web links

Activity

Show:

Former user September 11, 2019 at 6:26 PM

Fixed in 5.3 branch as well.

Former user August 22, 2019 at 7:24 PM

Fixed in master branch.

Fixed

Assignee

Yoann Rodière

Reporter

Components

Fix versions

Affects versions

Priority

Created August 20, 2019 at 8:12 AM
Updated September 12, 2019 at 3:38 AM
Resolved August 22, 2019 at 7:24 PM