Question

The JPA specification (2.1) says that:

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

What is the expected behavior after a @Version property overflows?

Was it helpful?

Solution

I would expect it to work correctly. No error occurs on overflow and version++ != version. It will result in the risk of overwriting updates if you're using short and have 65536 transactions with updates on this entity before the first one finishes.

Edit: when you use @Version, then update queries 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 = ?

now JDBC will return the update count upon completion. If no update has been made, then the JPA implementation will assume that no data with the specified id and version was found -> Exception.

OTHER TIPS

I can confirm EasterBunnyBugSmasher's answer on Hibernate 5. Defined a byte @Version field, once reached 128 went around to -127 and kept looping.

(I have no reputation to comment)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top