Hibernate : How to use collection to hold multiple values in entity

Single object reference can be defined in a straight forward way. Just define the datatype and column name would be automatically create by hibernate in schema. However, if one defines a collection to hold multiple values in hibernate, it is not that simple. One addition table is required to maintain the references with the identifiers of both values which are required to be stored.
@ManyToMany
@JoinTable(name = “shoppingcart_products”,
joinColumns = @JoinColumn(name = “user_id”),
inverseJoinColumns = @JoinColumn(name = “product_id”))
private Set shoppedProducts = new HashSet();

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s