I have a many-to-many association that is bi-directional between an Area class and an Item class. An area contains many Items and an item can be associated with many areas.
Using annotations, I have:
Code:
@Entity
@Table(name = "item")
public class Item {
private List<Area> areas;
@OneToMany(mappedBy = "items")
public List<Area> getLinkedAreas() {
return areas;
}
}
@Entity
@Table(name = "area")
public class Area {
/** List of objects that are connected to this area */
private List<Item> items = new ArrayList<Item>(0);
@ManyToMany
@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
public List<Item> getItems() {
return items;
}
}
This creates 3 tables in the DB:
Area Area_Item Item
When I delete an Item from the DB using:
Code:
Item a = this.findById(itemId);
session.delete(a);
I want it to also delete the association inside of the Area_Item table which links that Item to the Area... Can hibernate handle this for me? A cascade option?
Thanks,
Ray