I am using hibernate and a version column is provided for the hibernate locking purposes. The problem is that the app will update an entry often enough that the Java's int limit is reached by the version column. It is possible that the int limit of the MySQL is also reached.
Is there a way to make the version roll back to zero once it reaches any limit (Java's or MySQL's)?
Sure I can just enlarge the data type to be long. But it is just delaying the inevitable.
Edit: I googled around and found this annotation: @OptimisticLock(excluded=true). Link: http://bit.ly/nczCx1 It seems that it can theoretically work but I haven't successfully use it. Does anyone know how to properly use this annotation?
Okay, so you've reached the limit of integer, fair enough. When you increase it to, let say 'long' you have another four bytes available for you. Which is more than enough (it still just delays the inevitable, sure).
You can reach the old limit (of 2**32 updates) exactly 2**32 times, before it starts to overflow again. Lets assume it takes 1 seconds to have that many updates (I guess it took you longer), then it would take you another 2**32 seconds to (or about 136 years) to overflow a long.
But I don't know if there's a different elegant solution, but if there isn't I wouldn't waste the time for such details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With