You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Sebastian <no...@gmx.net> on 2003/12/22 18:02:16 UTC

auto-delete=true question

Hi,
I just discoverd the following behavior and I'm not sure if that works a
s designed. I'm using RC5.

That's the situation:

**********************************************************************
Class Parent
{
    int ID;
    RemovalAwareCollection childs = new RemovalAwareCollection();

    void removeChild(Child c)
    {
       childs.remove(c);
    }

    void addChild(Child c)
    {
       cholds.add(c);
    }
}

Class Child
{
    int ID;
    int parentID;
}

**********************************************************************
the Parent's collection descriptor for the childs property:
<collection-descriptor
    auto-retrieve="true" auto-delete="true" auto-update="true"
    refresh="true" name="childs"
collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollection"
    element-class-ref="Child"
>
   <inverse-foreignkey field-ref="parentID"/>
</collection-descriptor>

**********************************************************************
The problem:
When I add a child to the parent and store the parent, the child is also
written to the database. BUT when I then remove the child from the
parent's child collection and immediately delete the parent, the child
stays in the database table. On the opposite, when I store the parent
after I removed the child and then delete it the child is gone too.

This doesn't:
    Parent p = new Parent();
    Child c = new Child();
    p.addChild(c);
    broker.store(p);
    p.removeChild(c);
    broker.delete(p);
    //--> now the child is still in the table

This works:
    Parent p = new Parent();
    Child c = new Child();
    p.addChild(c);
    broker.store(p);
    p.removeChild(c);
    broker.store(p);
    broker.delete(p);

So my question is: is it ok the way OJB behaves or not?

Thanks in advance,
Sebastian



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: auto-delete=true question

Posted by Sebastian <no...@gmx.net>.
Thomas Mahler wrote:
> Hi Sebastian,
> 
> Did you read 
> http://db.apache.org/ojb/tutorial3.html#Setting%20Load,%20Update,%20and%20Delete%20Cascading 
> ?
> 
> You encounter the interference of two features here: the cascading 
> operations feature and the removal-aware collection.
> 
> 1. If you remove a Child and then delete the parent, The cascade feature 
> does only delete those elements currently present in the collection.
> 
> 2. If you remove a child and then store the parent, the removal aware 
> collection notices that the removed child should be removed in the db too.
> 
> ALthough this all works as designed, I have to admit that it may be a 
> bit confusing.
> Maybe it would be more consistent, if we would change the semantics of 
> 1. as follows:
> If you remove a Child and then delete the parent, the cascading feature 
> deletes the childs currently present in the collection and all removed 
> child objects?
> 
> cu,
> Thomas

Hello Thomas,
thanks for your quick response. I read the section you mentioned 
sometime before I encountered this issue, so I didn't have the exact 
definition in mind.
I of course can live with the "workaround" of saving the parent object 
first, but I would like to see the semantic change you described as it 
really makes sense and helps to avoid orphan entries in the database.

Regards,
Sebastian


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: auto-delete=true question

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi thomas,

Thomas Mahler wrote:
> Hi Sebastian,
> 
> Did you read 
> http://db.apache.org/ojb/tutorial3.html#Setting%20Load,%20Update,%20and%20Delete%20Cascading 
> ?
> 
> You encounter the interference of two features here: the cascading 
> operations feature and the removal-aware collection.
> 
> 1. If you remove a Child and then delete the parent, The cascade feature 
> does only delete those elements currently present in the collection.
> 
> 2. If you remove a child and then store the parent, the removal aware 
> collection notices that the removed child should be removed in the db too.

why don't we provide the same feature for insert ?

jakob
> 
> ALthough this all works as designed, I have to admit that it may be a 
> bit confusing.
> Maybe it would be more consistent, if we would change the semantics of 
> 1. as follows:
> If you remove a Child and then delete the parent, the cascading feature 
> deletes the childs currently present in the collection and all removed 
> child objects?
> 
> cu,
> Thomas
> 
> 
> 
> Sebastian wrote:
> 
>> Hi,
>> I just discoverd the following behavior and I'm not sure if that works a
>> s designed. I'm using RC5.
>>
>> That's the situation:
>>
>> **********************************************************************
>> Class Parent
>> {
>>    int ID;
>>    RemovalAwareCollection childs = new RemovalAwareCollection();
>>
>>    void removeChild(Child c)
>>    {
>>       childs.remove(c);
>>    }
>>
>>    void addChild(Child c)
>>    {
>>       cholds.add(c);
>>    }
>> }
>>
>> Class Child
>> {
>>    int ID;
>>    int parentID;
>> }
>>
>> **********************************************************************
>> the Parent's collection descriptor for the childs property:
>> <collection-descriptor
>>    auto-retrieve="true" auto-delete="true" auto-update="true"
>>    refresh="true" name="childs"
>> collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollection" 
>>
>>    element-class-ref="Child"
>>
>>>
>>   <inverse-foreignkey field-ref="parentID"/>
>> </collection-descriptor>
>>
>> **********************************************************************
>> The problem:
>> When I add a child to the parent and store the parent, the child is also
>> written to the database. BUT when I then remove the child from the
>> parent's child collection and immediately delete the parent, the child
>> stays in the database table. On the opposite, when I store the parent
>> after I removed the child and then delete it the child is gone too.
>>
>> This doesn't:
>>    Parent p = new Parent();
>>    Child c = new Child();
>>    p.addChild(c);
>>    broker.store(p);
>>    p.removeChild(c);
>>    broker.delete(p);
>>    //--> now the child is still in the table
>>
>> This works:
>>    Parent p = new Parent();
>>    Child c = new Child();
>>    p.addChild(c);
>>    broker.store(p);
>>    p.removeChild(c);
>>    broker.store(p);
>>    broker.delete(p);
>>
>> So my question is: is it ok the way OJB behaves or not?
>>
>> Thanks in advance,
>> Sebastian
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: auto-delete=true question

Posted by Thomas Mahler <th...@web.de>.
Hi Sebastian,

Did you read 
http://db.apache.org/ojb/tutorial3.html#Setting%20Load,%20Update,%20and%20Delete%20Cascading 
?

You encounter the interference of two features here: the cascading 
operations feature and the removal-aware collection.

1. If you remove a Child and then delete the parent, The cascade feature 
does only delete those elements currently present in the collection.

2. If you remove a child and then store the parent, the removal aware 
collection notices that the removed child should be removed in the db too.

ALthough this all works as designed, I have to admit that it may be a 
bit confusing.
Maybe it would be more consistent, if we would change the semantics of 
1. as follows:
If you remove a Child and then delete the parent, the cascading feature 
deletes the childs currently present in the collection and all removed 
child objects?

cu,
Thomas



Sebastian wrote:
> Hi,
> I just discoverd the following behavior and I'm not sure if that works a
> s designed. I'm using RC5.
> 
> That's the situation:
> 
> **********************************************************************
> Class Parent
> {
>    int ID;
>    RemovalAwareCollection childs = new RemovalAwareCollection();
> 
>    void removeChild(Child c)
>    {
>       childs.remove(c);
>    }
> 
>    void addChild(Child c)
>    {
>       cholds.add(c);
>    }
> }
> 
> Class Child
> {
>    int ID;
>    int parentID;
> }
> 
> **********************************************************************
> the Parent's collection descriptor for the childs property:
> <collection-descriptor
>    auto-retrieve="true" auto-delete="true" auto-update="true"
>    refresh="true" name="childs"
> collection-class="org.apache.ojb.broker.util.collections.RemovalAwareCollection" 
> 
>    element-class-ref="Child"
> 
>>
>   <inverse-foreignkey field-ref="parentID"/>
> </collection-descriptor>
> 
> **********************************************************************
> The problem:
> When I add a child to the parent and store the parent, the child is also
> written to the database. BUT when I then remove the child from the
> parent's child collection and immediately delete the parent, the child
> stays in the database table. On the opposite, when I store the parent
> after I removed the child and then delete it the child is gone too.
> 
> This doesn't:
>    Parent p = new Parent();
>    Child c = new Child();
>    p.addChild(c);
>    broker.store(p);
>    p.removeChild(c);
>    broker.delete(p);
>    //--> now the child is still in the table
> 
> This works:
>    Parent p = new Parent();
>    Child c = new Child();
>    p.addChild(c);
>    broker.store(p);
>    p.removeChild(c);
>    broker.store(p);
>    broker.delete(p);
> 
> So my question is: is it ok the way OJB behaves or not?
> 
> Thanks in advance,
> Sebastian
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org