optimistic locking maybe your solution. Try adding a @Version field to your Studient entity class. Then client2 will be aborted.
You would have to use the Hibernate APIs to perform a pessimistic lock.
So, Do I have to use @Version in all Entities? Is there a performance/other kind of problem/drawback doing that?
The behavior you i've got is known as the secfond lost update issue.
To solve that:
- use repeteable read for your JDBC tx isolation level
- or use read_commited + optimistic locking (ie @Version)
@Version as no known drawbacks nor perf cost if you can afford adding a version column in your relational model