Due to historical reasons, we are using a Session-per-application pattern in our java desktop application. Loaded objects are detached after session close. After migration from 4.1.9 to 5.2.12, these objects are now detached after a transaction callback operation.
How to set the transaction scope to Extended Persistence context in Hibernate 5.2?
An object is detached only after you close the Session, not after a transaction operation. More, you can span a single Session across multiple subsequent transactions without needing to use an Extended Persistence Context.
Calling operation mySession.contains(myEntity) returns false after executing mySession.getTransaction().rollback()
That’s a JPA requirement. This is an excerpt from the spec:
3.3.3 Transaction Rollback
For both transaction-scoped persistence contexts and for extended persistence contexts that are joined to
the current transaction, transaction rollback causes all pre-existing managed instances and removed
instances[31] to become detached.