我正在使用Play的CRUD模块来创建一组简单的管理屏幕.我的一个模型是用户,我想在电子邮件字段上强制执行唯一约束.
代码如下所示:
public class User extends Model {
@Email
@Required
@Column(unique=true)
public String email;
Run Code Online (Sandbox Code Playgroud)
管理屏幕正确显示 - 当我尝试打破唯一性时(通过使用已使用过的电子邮件保存用户)我收到此错误(在浏览器中):
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:
}
Run Code Online (Sandbox Code Playgroud)
我可以使用CRUD模块和列唯一性注释进行任何调整吗?