wood burning stoves 2.0*
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
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
 
jQuery in Action, 2nd edition
 
subject: How to update an entity in a collection
 
Similar Threads
Design issue: caching hierarchical tree of data, read-mostly
Sending response to client with out receving request
One-to-Many Bidirectional Inverse Issue
Regarding CheckBoxSelectionModel usage in EXT JS
Using @JoinColumn VS not using @JoinColumn