Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to update an entity in a collection

 
Roger Rustin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic