I am using Ebean with Play Framework 2 and sometimes it falls with OptimisticLockException of such kind:
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[OptimisticLockException: Data has changed. updated [0] rows sql[update manager set modification_time=?, session_id=?, expiration_date=? where id=? and rating=? and creation_time=? and modification_time=? and name=? and surname=? and login=? and password_hash=? and email=? and session_id=? and expiration_date=?] bind[null]]]
This happen when few actors start to access database.
So, Manager class is:
public class Manager extends Model {
@Getter @Setter
Long id;
@Getter @Setter
private String name;
@Getter @Setter
private String surname;
@Column(unique = true)
@Getter @Setter
private String login;
@Getter @Setter
private String passwordHash;
@Getter @Setter
private String email;
@Embedded
@Getter @Setter
private ManagerSession session;
@Getter
private Timestamp creationTime;
@Getter
private Timestamp modificationTime;
@Override
public void save() {
this.creationTime = new Timestamp(System.currentTimeMillis());
this.modificationTime = new Timestamp(System.currentTimeMillis());
super.save();
}
@Override
public void update() {
this.modificationTime = new Timestamp(System.currentTimeMillis());
super.update();
}
}
save() and update() hooks used instead @PrePersist annotations, because of Ebean doesn't support it. As I know @Version annotation allways brings Optimistic lock mode, so I start to use such trick. I know what Optimistick lock is, but how this situation should be solved, when many actors should modify same db record, where last modification wins?