Here's the official description of
hibernate.transaction.flush_before_completion Code:
hibernate.transaction.flush_before_completion
If enabled, the session will be automatically flushed during the before completion phase of the transaction.
Built-in and automatic session context management is preferred, see Section 2.5, “Contextual sessions”.
e.g. true | false
The sentence "Built-in and automatic session context management is preferred" is rather confusing!
What means 'preferred' exactly in this context ?!
Does is mean that 'Programmatic transaction demarcation' has become obsolete or a 'anti-pattern'?
Why is
hibernate.transaction.flush_before_completion automatically set to false
if using the Enititymanger ?
Anyway following code-lines in org.hibernate.ejb.Ejb3Configuration#prepareProperties(Properties properties, Map workingVars)
are responsible for the described trouble:
Code:
if ( hasTxStrategy ) {
log.warn(
"Overriding {} is dangerous, this might break the EJB3 specification implementation",
Environment.TRANSACTION_STRATEGY
);
}
if ( preparedProperties.getProperty( Environment.FLUSH_BEFORE_COMPLETION ).equals( "true" ) ) {
preparedProperties.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "false" );
log.warn( "Defining {}=true ignored in HEM", Environment.FLUSH_BEFORE_COMPLETION );
}
On page 446 of the book 'Java persistence with Hiberante' there's described:
... on the other hand, you can enable the
hibernate.transaction.flush_before_completion ... configuration options an let Hibernate take care of this for you again.