Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collections Mapping vs Association mapping

I am very newbie to hibernate. I am learning about Mappings in hibernate in which case i have to go for Collection Mapping and Association Mapping. My confusion is "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"

in that case why we go for collection instead of onetomany. Please provide a simple real time example for when we use collection and association mapping

like image 728
jackyesind Avatar asked Jun 27 '26 12:06

jackyesind


1 Answers

I think you are confused in Collection and Association.

It is not necessary that every association must be a single Object, it can be collection of Objects.

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

See : http://www.mkyong.com/hibernate/hibernate-one-to-many-relationship-example-annotation/

like image 179
Anil Bharadia Avatar answered Jun 30 '26 22:06

Anil Bharadia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!