Inconsistent behaviour when running without transactions

Description

Problem 1)
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.

Problem 2)
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.

Problem 3)
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
configuration.setProperty(AvailableSettings.ALLOW_UPDATE_OUTSIDE_TRANSACTION, Boolean.TRUE.toString());

Environment

None

Activity

Show:
Andrea Boriero
February 13, 2018, 12:04 PM

Hi ,
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.

Radoslav Petrov
February 13, 2018, 6:55 PM

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:

Andrea Boriero
February 14, 2018, 10:36 AM

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"

Radoslav Petrov
February 16, 2018, 7:53 AM

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).

Assignee

Unassigned

Reporter

Radoslav Petrov

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure