We are moving from Hibernate 4 to Hibernate 5 with our move from JBoss 7 to Wildfly 10.
One thing we have noticed is that when we execute a native query via the entityManager, a flush() is always executed prior to the query execution regardless of whether the flush mode is set to MANUAL or not. This is not how it worked in Hibernate 4.
One thing we have noticed is that when we execute a native query via the entityManager, a flush() is always executed prior to the query execution regardless of whether the flush mode is set to MANUAL or not. This is not how it worked in Hibernate 4.
That’s how JPA AUTO flush mode works and it’s better than the legacy AUTO mode which did not flush for native SQL queries. Not flushing for native SQL can break read-your-write consistency.
Now, if you set the flush mode to MANUAL and you still get an automatic flush, it means there is an issue. You need to replicate it and open a Jira issue.
Is there a way to control this via configuration?
To get the Hibernate-specific AUTO flush mode you need to bootstrap via Hibernate native mechanism, not via JPA. However, since you are using JBoss, I doubt you could do that. If you were using Spring, it might work if you use HibernateTransactionManager instead of JpaTransactionManager.