【发布时间】:2013-12-02 22:15:26
【问题描述】:
我有一个使用 Ebean 的 Play 2.1.3 Java 应用程序。我收到下面的 OptimisticLockException。
[OptimisticLockException: Data has changed. updated [0] rows sql[update person
set name=? where id=? and email=? and name=? and password is null and created=?
and deleted is null] bind[null]]
我知道它试图告诉我记录在我阅读和尝试写入之间发生了变化。但唯一的变化发生在这种方法中。
public void updateFromForm(Map<String, String[]> form) throws Exception {
this.name = form.get("name")[0];
String password = form.get("password")[0];
if (password != null && password.length() != 0) {
String hash = Password.getSaltedHash(password);
this.password = hash;
}
this.update();
}
我做错了吗?我在 zentasks 中看到了类似的逻辑。另外,我应该能够看到绑定变量的值吗?
更新:我从控制器内部调用 updateFromForm():
@RequiresAuthentication(clientName = "FormClient")
public static Result updateProfile() throws Exception {
final CommonProfile profile = getUserProfile();
String email = getEmail(profile);
Person p = Person.find.where().eq("email", email).findList().get(0);
Map<String, String[]> form = request().body().asFormUrlEncoded();
if (p == null) {
Person.createFromForm(form);
} else {
p.updateFromForm(form);
}
return ok("HI");
}
【问题讨论】:
-
能否包含调用
updateFromForm的方法? -
好的,我更新了。我在控制器内调用 updateFromForm() 。 updateFromForm 本身是在模型中定义的。您知道吗?我应该在错误消息中看到绑定变量的值吗?感谢您的帮助。
标签: java jpa playframework playframework-2.1 ebean