EntityManager.find() should only check for roll-back-only condition if there is an active JTA transaction, otherwise ORM should throw convert( e, lockOptions )

Description

added a check for roll-back-only condition, however, we should first check for active JTA transaction. The reason is that when Hibernate ORM calls accessTransaction().getRollbackOnly(), an ISE exception is immediately thrown by org.hibernate.engine.transaction.internal.TransactionImpl.getRollbackOnly, which is confusing to users, as they called EntityManager.find(), which shouldn't throw "IllegalStateException: JPA compliance dictates throwing IllegalStateException when #getRollbackOnly is called on non-active transaction", as the application didn't call #getRollbackOnly.

I suggest a change from:

Change instead to:

I'll try the above change locally and check if the current ORM testsuite still passes (on ORM master branch).

Environment

None

Activity

Show:
Scott Marlow
June 11, 2019, 2:28 PM

I marked this bug as minor, as I think that reflects it having minor impact but at the same time is highly annoying, due to the confusion it causes the user (as to why they are getting the exception about "#getRollbackOnly", when they only called EntityManager.find().

Scott Marlow
June 11, 2019, 2:33 PM
Edited

Pushed https://github.com/scottmarlow/hibernate-orm/tree/HHH-13433_master + https://github.com/scottmarlow/hibernate-orm/tree/HHH-13433_53.

I verified that this code change didn't seem to cause any (additional) tests to fail. Will push the change to get CI feedback.

Gail Badner
September 12, 2019, 2:54 AM

I’m not sure if this will work in all cases. I’m going to have to move it to 5.3.13, and look into it further.

Gail Badner
November 8, 2019, 4:33 AM

Fixed in master.

Gail Badner
January 7, 2020, 8:06 PM

Fixed in 5.3 branch as well.

Assignee

Scott Marlow

Reporter

Scott Marlow

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Minor
Configure