如何在EclipseLink/JPA中指定@OneToMany的基数 [英] How to specify the cardinality of a @OneToMany in EclipseLink/JPA

查看:126
本文介绍了如何在EclipseLink/JPA中指定@OneToMany的基数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图强加@ Oneto7关联.我曾经想象过一个可以指定目标许多值的属性,但是却找不到任何属性. 如果没有这样的属性,那么在JPA/EclipseLink中还能实现什么呢?

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 attribute, how else, in JPA/EclipseLink would one achieve it?

推荐答案

您可以使用Bean验证API( JSR-303 )-Hibernate Validator作为RI-并在您的集合上添加Size约束:

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>();

如果您使用的是JPA 1.0,请查看此上一个答案了解如何在JPA 1.0中使用Bean验证.

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.

这篇关于如何在EclipseLink/JPA中指定@OneToMany的基数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆