Showing posts with label hibernate delete remove. Show all posts
Showing posts with label hibernate delete remove. Show all posts

Friday, June 26, 2009

Remove from Hibernate Set

Suppose you have one-to-many bi-directional mapping between Category and Item.

public class Category {
Set items;
}

public class Item {
Category category;
}

To remove an item from Category, you need to do this

category.getItems.remove(item1);
delete(item1); // delete() is from Hibernate API

The first line takes out the relationship while the second one deletes it.