This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes How to update an entity in a collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to update an entity in a collection" Watch "How to update an entity in a collection" New topic
Author

How to update an entity in a collection

Roger Rustin
Greenhorn

Joined: Jul 08, 2004
Posts: 19
Hi,

I have an entity called category. A category can have many items. I am using "set" to have an association between categoty and items.

So I get the list of items like this.

Set items = category.getItems()

Now I need to update an item in the retrieved list. There are two ways I could think of

1) Using the item id get the itme from the DB and update the itme. In this case the category doesn't come into picture.
2) Update the set with the updated item and then save category. I have set cascade="all" so it should work. But in this case it will be a new set and then hibernate will delete all the items in the set and will populate them again.

Was just wondering what's the best practices.

thanks.
- Roger
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update an entity in a collection