Thursday, March 17, 2011

hibernate DefaultAutoFlushEventListener.onAutoFlush

this explains very well


"The Session is sometimes flushed before query execution in order to ensure that queries never return stale state. This is the default flush mode. "

using FlushModeType.COMMIT

improves a LOT performance, because flushing is an expensive operation.
But the result can be undetermined, and in fact my application now breaks because "find" queries don't find non-flushed entities:

see here

"If FlushModeType.COMMIT is set, the effect of updates made to entities in the persistence context upon queries is unspecified. "

:o))) I love working with unspecified products! Such a thrill!
These APIs were designed by lawyers.

Here it says explicitely:

Set flushes to occur at commit or before query execution. If
the flush mode is set to FlushModeType.COMMIT, changes
made during the transaction might not be visible in the
query execution results.

No comments: