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?
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.
short
, in which case it only takes 32k updates. – Javier