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.

No comments:

Post a Comment