Re: Deleting items in collection?

Carlos Chávez <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Organization AG Software, S.A.
Message-ID <[email protected]>
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]
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.