I'm having a bit of trouble mapping the following:
public class Operation {
private Integer id;
private String name;
private List<Item> items = new ArrayList<Item>();
//set/getters/hashcode/etc. omitted
public void addItem(Item i,Operation end) {
i.setOperationStart(this);
i.setOperationEnd(end};
items.add(i);
end.getItems().add(i);
}
public class Item {
private Integer id;
private String name;
private Operation operationStart;
private Operation operationEnd;
//set/getters/hashcode/etc. omitted
}
So basically an Operation have a bunch of Items, and an Item belongs to 2 Operations. Also, it doesn't make sense for an item to exist if one of the Operations doesn't exist, i.e. if I delete one of the Operations, I want to remove the item from wherever else it's stored as well.
Does anyone have a pointer on how I'd map the above classes, or could point me to some examples showing how to map a child object that has 2 parents ?