@OneToMany映射列表大小限制 [英] @OneToMany mapping list size limit
本文介绍了@OneToMany映射列表大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法限制JPA中@OneToMany关系的列表大小?
这是我的代码示例:
Is there any way to limit the list's size of the @OneToMany relationship in JPA? Here's my code sample:
@OneToMany(mappedBy = "publication", cascade=CascadeType.PERSIST)
private List<Comment> commentList;
我正在使用EclipseLink 2.3 JPA实现。
提前致谢。
I'm using EclipseLink 2.3 JPA implementation. Thanks in advance.
推荐答案
Bean验证规范(JSR-303)的一部分是 @Size(min =,max =)
注释:
Part of the Bean Validation Specification (JSR-303) is the @Size(min=, max=)
annotation:
支持的类型是String,Collection,Map和数组。检查带注释的元素大小是否在最小值和最大值(包括)之间。
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;
这篇关于@OneToMany映射列表大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文