JPA overflow @Version

The JPA specification (2.1) states that:

The following types are supported for version properties: int, Integer, short, Short, long, Long, Timestamp

What is the expected behavior after overflowing the @Version property?

+6
source share
2 answers

I expect it to work correctly. Error on overflow and version ++! =. This will lead to the risk of overwriting updates if you use a short code and have 65536 transactions with updates to this object until the first is completed.

Edit: when you use @Version, then update requests will not look like this:

 update person set surname = ? where id = ? 

but like this:

 update person set surname = ?, version_field = ? where id = ? and version_field = ? 

JDBC will now return the number of updates after completion. If the update was not performed, the JPA implementation assumes that no data with the specified identifier and version was found β†’ Exception.

+4
source

I can confirm EasterBunnyBugSmasher's answer in Hibernate 5. The specific byte @Version field, when reached 128, went to -127 and continued the loop.

(I have no reputation for comment)

-1
source

All Articles