Re: Deleting items in collection?
Edson Carlos Ericksson Richter <[email protected]>
| Newsgroups | gmane.comp.jakarta.ojb.user |
|---|---|
| Message-ID | <[email protected]> |
I've been using RemovalAwareList in the descriptor, so I don't need to take care of this in coding. Regards, Richter Carlos Chávez escreveu: > Sebastian Stein escribió: >> Vasily Ivanov <[email protected]> [060821 23:46]: >> >>>> if I delete an ClassB object from the collection in >>>> ClassA and store the ClassA object again, this >>>> ClassB object is not removed from the database >>>> >>> It depends on how you delete this object from collection. You should >>> get object (aObject) with all references using OJB query, first. Than >>> remove object (bObject) from collection (by calling >>> aObject.getBs().remove(bObject)) and than call broker.store(aObject). >>> That should remove bObject from db. >>> >> >> I really don't understand why it is not working. I do the following: >> >> aObject.getBs().clear(); >> aObject.getBs().addAll(newBs); >> >> But the old Bs are not removed, just the new Bs are added. This is >> the case >> if I have auto-delete="false" in the repository.xml for the >> definition of >> the objectB collection. >> >> If I turn it on, it deletes all Bs without adding them again. It is very >> strange. >> >> > Hi Sebastian. > > We had some similar situation, we solved in this way: > > OBJ have a RemovalAwareList class, so i create a List usign > RemovalAwareList(), copy the childs to this > list, then remove the object from the list then i commit the changes. > > Example: > List lst = new RemovalAwareList(); > lst.addAll(object1.getChilds()); > lst.remove(child); > object1.setChilds(lst); So when you commit your > changes OJB delete the object. > > I hope this help. > > Cheers, > Carlos Chávez. >> Sebastian >> >> PS: If you are interested I can also point you directly to the code, >> it is >> public. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]