문제

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.

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top