【发布时间】:2011-08-31 21:01:50
【问题描述】:
我正在使用 Play 的 CRUD 模块来创建一组简单的管理屏幕。我的模型之一是用户,我想对电子邮件字段强制执行唯一约束。
代码如下:
public class User extends Model {
@Email
@Required
@Column(unique=true)
public String email;
管理屏幕正确显示 - 当我尝试破坏唯一性时(通过保存已使用电子邮件的用户)我收到此错误(在浏览器中):
Execution exception
PersistenceException occured : org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
In {module:crud}/app/controllers/CRUD.java (around line 100)
96:
} catch (TemplateNotFoundException e) {
97:
render("CRUD/show.html", type, object);
98:
}
99:
}
100:
<b>object._save();</b>
101:
flash.success(Messages.get("crud.saved", type.modelName));
102:
if (params.get("_save") != null) {
103:
redirect(request.controller + ".list");
104:
}
105:
redirect(request.controller + ".show", object._key());
106:
}
我可以对使用 CRUD 模块和列唯一性注释进行任何调整吗?
【问题讨论】:
标签: hibernate frameworks playframework crud unique-constraint