Refreshing an entity clears the lock mode returned from EntityManager.getLockMode

Description

When an entity has been locked within a transaction and later a refresh is invoked upon it this causes EntityManager.getLockMode to return the standard OPTIMISTIC lock mode type (indicating not locked).

e.g.

A simple project has been included which illustrates this.

Environment

None

Activity

Show:
Caspian Borison
January 31, 2018, 11:29 PM
Edited

, thanks for the update!

after discussing on the hibernate-dev mailing list, we agree that this is a bug.

Good news; thanks for looking into this! Maybe once such changes are live I can convince my various project teams to finally upgrade.

It appears that the original database lock in the first transaction blocks the load from the second transaction. Did you see this behavior as well?

In other words, in your testing, did you actually find that the database lock was released after refreshing, and that a second transaction was able to update the entity?

Yes, the behavior you observed is the behavior I find as well. Refreshing an entity does not release the database locks (I do not believe it's even possible to release a database lock without a rollback/commit). The locking semantics within the actual database transactions are correct - it is just the lock mode within the session/entity manager that is getting out of sync.

Gail Badner
February 1, 2018, 2:28 AM

, thanks for the feedback!

Steve Ebersole
April 18, 2018, 3:43 PM

Waiting on feedback from wrt PR

Steve Ebersole
April 25, 2018, 1:21 PM

Going to unschedule this soon...

Gail Badner
April 26, 2018, 7:56 PM

Fixed in master and 5.2 branches.

Assignee

Gail Badner

Reporter

Caspian Borison

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure