我使用Ebean有Play框架2,有時用這樣那樣的OptimisticLockException下降:OptimisticLockException與Ebean和播放框架2
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]]]
這時候幾個演員開始訪問數據庫的發生。
所以,經理類是:
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();
}
}
節省代替@PrePersist註解()和update()掛鉤,因爲Ebean不支持它。 正如我所知@Version註釋allways帶來樂觀鎖定模式,所以我開始使用這種技巧。我知道Optimistick鎖是什麼,但是如何解決這種情況,當許多演員應該修改相同的數據庫記錄,最後修改獲勝?
是的,你說得對。但是我的麻煩不在這裏。問題出現在類層次結構深處的@Version註釋中。 無論如何,對於第一次面對這樣的麻煩的人來說,你的答案是非常有用的。讓它被接受。 –
如何在表單綁定之前獲得** id **來調用* Venue.find.byId(id))*? –