Using AvailableSettings.ALLOW_UPDATE_OUTSIDE_TRANSACTION = "true" with FlushMode.ALWAYS: the inserts are automatically saved to the DB without need to call flush(). But the update does NOT behave the same way - there is no warning or anything, just the old data.
Using AvailableSettings.ALLOW_UPDATE_OUTSIDE_TRANSACTION = "true" with FlushMode.AUTO: neither the inserts or the updates are saved to the DB and there is NO warning. But if a flush() is called the data is saved.
Without AvailableSettings.ALLOW_UPDATE_OUTSIDE_TRANSACTION = "true" i.e. the pre Hibernate 5.2 behaviour the same test cases behave VERY differently: the insert with FlushMode.ALWAYS doesn't save to the DB and no warnings or anything in the log. It fails in the same way as the case [no transaction, FlushMode.AUTO, no flush].
The test case class is called NoTransaction.java. To access problem 3) just comment the line:
//Comment and uncomment the following line to get all permutations of the problem
first I noticed you tests are not isolated, you forget to clean up the database after each test, so the order of execution matter, having the 2 tests updateNoTxWithFlush and createNoTransactionWithFlush influencing the results of the others.
If you clean up the db after each test execution you will notice that only the 2 tests where the flush method is called manually will pass.
I also tried your tests with 5.1.11 and 5.0.12 and I have the same behaviour of 5.2.12.
Anyway apart suggesting you to always use transactions, in case you don't want you always need to flush manually in order to be sure to have the data persisted.
Ohhh, I see my mistake. Thank you very much.
Could you point me where this behaviour is documented?
I haven't found mention of it in the following:
http://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/FlushMode.html - According to the above this is not relevant at all when no transaction is present;
JPA 2.1 specification section 3.10.8 Queries and Flush Mode states that "If there is no transaction active, the persistence provider must not flush to the database"
Thank you very much. This was quite a long shot for me. Basically the Hibernate ORM adheres to the JPA specs even when we are using it outside the specification (in this case - not using transactions).