集合映射与关联映射

时间:2013-03-15 09:28:19

标签: hibernate hibernate-mapping

我是休眠的新手。我正在学习hibernate中的Mappings,在这种情况下我必须去收集映射和关联映射。我的困惑是“If an entity or class has collection of values for a particular variable, then we can map those values using any one of the collection interfaces available in java

在这种情况下,为什么我们去收集而不是onetomany。请提供一个简单的实时示例,说明何时使用收集和关联映射

2 个答案:

答案 0 :(得分:1)

我认为你在收藏和协会中感到困惑。

每个关联都不必是单个对象,它可以是对象的集合。

@OneToMany(fetch = FetchType.LAZY, mappedBy = "stock")
public Set<StockDailyRecord> getStockDailyRecords() {
    return this.stockDailyRecords;
}

请参阅:http://www.mkyong.com/hibernate/hibernate-one-to-many-relationship-example-annotation/

答案 1 :(得分:0)

集合映射和关联映射不具有可比性,我的意思是这些映射驻留在不同的抽象层上,如果需要,关联映射使用集合映射。