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?
@OptimisticLock(excluded=true) works! I just forgot to make sure that I put it on every updated properties. It disallows the version number to be incremented as promised.
Example:
@Entity
@Table(name="some_table")
public class SomeEntity extends BaseEntity {
//... some code
@Column
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@OptimisticLock(excluded=true)
private DateTime lastUsed = new DateTime();
//... some code
}
This way, even if the lastUsed properties is updated (and persisted), the version would not increase.