简体   繁体   English

hibernate中的一对多关联

[英]one to many association in hibernate

The hibernate documentation gives some rules when we use one-to-many association in Hibernate: 当我们在Hibernate中使用一对多关联时,hibernate文档提供了一些规则:

http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/collections.html#collections-onetomany http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/collections.html#collections-onetomany

A one-to-many association links the tables of two classes via a foreign key with no intervening collection table. 一对多关联通过外键链接两个类的表,而没有中间收集表。 This mapping loses certain semantics of normal Java collections: 此映射丢失了普通Java集合的某些语义:

  • An instance of the contained entity class cannot belong to more than one instance of the collection. 包含的实体类的实例不能属于该集合的多个实例。
  • An instance of the contained entity class cannot appear at more than one value of the collection index. 包含的实体类的实例不能出现在集合索引的多个值中。

Please help me in understanding these statements. 请帮助我理解这些陈述。

Suppose I have a Product and it has collection of parts, now as per the points what kind of restrictions applied on my Product and its parts? 假设我有一个产品并且它有零件集合,现在根据这些要点对我的产品及其零件施加了什么样的限制?

  • A Part cannot belong to 2 or more Products 部件不能属于2个或更多产品
  • A Part cannot appears more than one time in the Collection of Parts of a Product 零件在产品零件集合中不能出现多次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM