Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA @Version overflow

Tags:

java

jpa

jpa-2.0

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?

like image 784
Javier Avatar asked May 14 '14 15:05

Javier


1 Answers

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.

like image 108
EasterBunnyBugSmasher Avatar answered Sep 22 '22 02:09

EasterBunnyBugSmasher