Completed access paths for Criteria and collection-valued queries
As before, a query with FlushModeType.AUTO (the default, openjpa.FlushBeforeQueries=true) flushes pending changes only when a new, dirty or deleted instance belongs to a type in the query’s access path, that is to a type the query actually reads.
This is what section 3.10.8 of the specification asks for: the duty covers the updates "which could potentially affect the result of the query", and the provider may discharge it "by flushing those entities to the database or by some other means".
What changed is that the access paths themselves are now complete, so queries that failed to flush a relevant change do so.
For a Criteria query a type reached through an implicit join (a path navigated with Path.get), through a join of a join, through a fetch join, inside a subquery or behind a join of a correlated join used to be left out.
For JPQL, a collection- or map-valued path used without a join variable - SIZE(x.coll), x.coll IS EMPTY - did not contribute its element and key types, because the declared type of such a field is Collection or Map.
A dirty instance of any of those types was not flushed before the query ran, which could yield a stale result; such a query now flushes where it did not before.
openjpa.IgnoreChanges=true is unchanged and keeps its documented effect for every SELECT, whatever the flush mode of the query is.
It is an OpenJPA extension that deliberately opts a SELECT out of the visibility guarantee of section 3.10.8; the specification states that guarantee equally for a flush mode set on the query object and for one inherited from the persistence context, so the option is not overridden by either.