@Entity
public class Person {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private int salary;
@Version
private long version;
// ...getters and setters
}
- Is it required to create setter/getter for
version? - When persisting this entity with Hibernate, I don’t need to set this value manually, right?
- What else do I need to configure in order to use optimistic concurrency checking with Spring’s
hibernateTemplate.saveOrUpdate? Are all databases supported? - How to unit-test this entity? In my database all my records showing version field have value of 0
- Will calling
hibernateTemplate.saveOrUpdateincrement the version value every time?
I would say:
To see version values more than 0, read/modify/update your entity in a transaction, the version increase by one. Go out of the transaction, do it again, the value increases …