Hi,
I'm currently removing persistent objects (child objects already saved to DB) from collections like this (simplified code version):
Parent parent = (Parent) parentDAO.getObject(Parent.class, new Long(1));
Child child = (Child) childDAO.getObject(Child.class, new Long(request.getParameter("childId")));
parent.getChildren().remove(child);
parentDAO.saveObject(parent);
... which works.
My first question is, is there anyway to remove an already persistent object from a Set without pulling out an instance of it from the backend first to get a handle on it?
The problem im having is that the only info I get on which child to remove is the child's ID (which is typical) and I found that initializing a new object with that ID to try to leverage equals() and using Set.remove() wont work.
My second question is, for the same scenario, how do I remove a child that has not yet been saved yet to database (unsaved-value == null). Seems the only thing I can think of is to change the child's equals value to compare all fields and iterate one by one till i get the match, then use that object to remove itself from the collection...
Any input would be appreciated.
Thanks,
-Yves-
|