开发者

How to specify the cardinality of a @OneToMany in EclipseLink/JPA

开发者 https://www.devze.com 2022-12-27 21:04 出处:网络
I\'m trying to impose a @Oneto7 association. I\'d have imagined an attribute that specifies the target many value, but have found none.

I'm trying to impose a @Oneto7 association. I'd have imagined an attribute that specifies the target many value, but have found none. If there is no such attri开发者_如何学运维bute, how else, in JPA/EclipseLink would one achieve it?


You could use the Bean Validation API (JSR-303) - Hibernate Validator being the RI - and add a Size constraint on your collection:

@Size(min = 7, max = 7) protected Set<Foo> foos = new HashSet<Foo>();

If you're using JPA 1.0, have a look at this previous answer to see how to use Bean Validation with JPA 1.0.


You may use the Oval library and set e.g.:

@OneToMany(cascade = CascadeType.ALL, mappedBy = "whatevery")
@Size(max = 30)
private List<SuperDocument> documents;

Here is the documentation for further validations of Oval: http://oval.sourceforge.net/userguide.html#api-documentation

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号