java – @OneToMany映射列表大小限制

有没有办法限制JPA中@OneToMany关系的列表大小?
这是我的代码示例:

@OneToMany(mappedBy = "publication", cascade=CascadeType.PERSIST)
private List<Comment> commentList;

我正在使用EclipseLink 2.3 JPA实现.
提前致谢.

最佳答案
Bean验证规范(JSR-303)的一部分是@Size(min =,max =)注释:

Supported types are String, Collection, Map and arrays. Check if the annotated element size is between min and max (inclusive).

您可以验证该集合.

@OneToMany(mappedBy = "publication", cascade=CascadeType.PERSIST)
@Size(min=1, max=10)
private List<Comment> commentList;

转载注明原文:java – @OneToMany映射列表大小限制 - 代码日志