StaleObjectStateException into a SINGLE transaction for entity with version field of type java.util.Date

Description

He team! We got stuck with the following issue: StaleObjectStateException arises during the update execution into the SINGLE transaction.

Feel free to look and clone the minimal example from bitbucket:
https://bitbucket.org/gegunov/hibernate_issue
WIKI with examples are also attached there.

Steps to reproduce:

prerequisites:

  • Table DDL

  • Entity class with fields: 1) of type java.util.Date annotated by @Version e.g lastUpdateDate
    2) of type java.util.String for state
    3) of type Long (for Id)

  1. Create entity having any state.

  2. Then in the other transaction execute the following steps:

    1. find the created entity with entityManager.find

    2. update the field state (of type String)

    3. execute another one select from database using entityManager. It doesn't matter what it will return. It could even return nothing. In the provided code I deliberately use keys which not exist in DB

    4. update the entity again with different value.

  3. When the transaction is being committed it will fail with the following error
    org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

It should be said that the mentioned behavior is not reproduced with the version field of type short, only with java.util.Date

Environment

None

Assignee

Unassigned

Reporter

Глеб Егунов

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Priority

Major
Configure