You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Armin Waibel <ar...@code-au-lait.de> on 2003/12/06 19:05:30 UTC

[Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Hi all,

I think I found a bug? in PBImpl class on delete of the 1:n relations of 
the main object when auto-delete is set true in metadata.

Say we have a Product class and a Component class, Product has a 1:n 
relation to Component and we set auto-delete in collection-descriptor.

Product
{
id
name
components
}

Component
{
id
name
productId
}

1. auto-retrieve is set true and we query a Product, then we get all 
Components from Product and remove some components (or set components 
'null'). After this we delete this Product instance ---> auto-delete is 
true, thus all found components will be deleted (without the removed) 
BUT we should delete all components associated with this Product instance.

2. auto-retrieve is set false. Get a Product and delete it. Since we set 
auto-delete true we expect that all associated Components will be 
deleted too.

Or do I misinterpret the 'auto-delete' flag?

regards,
Armin



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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Antonio Gallardo dijo:
> Hi Armin:
>
> The exposed behavior works well to me. The only diference I have is that
> in O/R mapping we don't use the "auto-retrieve" attribute at all.
>
> Best Regards,
>
> Antonio Gallardo

Sorry, I review it again:

Since we don't set auto-retrieve attribute, then it is true by default.
Note we also use auto-update="true" to get the behavior you exposed below.

I hope this would help.

Best Regards,

Antonio Gallardo

>
> Armin Waibel dijo:
>> Hi all,
>>
>> I think I found a bug? in PBImpl class on delete of the 1:n relations of
>> the main object when auto-delete is set true in metadata.
>>
>> Say we have a Product class and a Component class, Product has a 1:n
>> relation to Component and we set auto-delete in collection-descriptor.
>>
>> Product
>> {
>> id
>> name
>> components
>> }
>>
>> Component
>> {
>> id
>> name
>> productId
>> }
>>
>> 1. auto-retrieve is set true and we query a Product, then we get all
>> Components from Product and remove some components (or set components
>> 'null'). After this we delete this Product instance ---> auto-delete is
>> true, thus all found components will be deleted (without the removed)
>> BUT we should delete all components associated with this Product
>> instance.
>>
>> 2. auto-retrieve is set false. Get a Product and delete it. Since we set
>> auto-delete true we expect that all associated Components will be
>> deleted too.
>>
>> Or do I misinterpret the 'auto-delete' flag?
>>
>> regards,
>> Armin
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>


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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Armin:

The exposed behavior works well to me. The only diference I have is that
in O/R mapping we don't use the "auto-retrieve" attribute at all.

Best Regards,

Antonio Gallardo

Armin Waibel dijo:
> Hi all,
>
> I think I found a bug? in PBImpl class on delete of the 1:n relations of
> the main object when auto-delete is set true in metadata.
>
> Say we have a Product class and a Component class, Product has a 1:n
> relation to Component and we set auto-delete in collection-descriptor.
>
> Product
> {
> id
> name
> components
> }
>
> Component
> {
> id
> name
> productId
> }
>
> 1. auto-retrieve is set true and we query a Product, then we get all
> Components from Product and remove some components (or set components
> 'null'). After this we delete this Product instance ---> auto-delete is
> true, thus all found components will be deleted (without the removed)
> BUT we should delete all components associated with this Product instance.
>
> 2. auto-retrieve is set false. Get a Product and delete it. Since we set
> auto-delete true we expect that all associated Components will be
> deleted too.
>
> Or do I misinterpret the 'auto-delete' flag?
>
> regards,
> Armin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>


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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Thomas,

Thomas Mahler wrote:

>> 1. auto-retrieve is set true and we query a Product, then we get all 
>> Components from Product and remove some components (or set components 
>> 'null'). After this we delete this Product instance ---> auto-delete 
>> is true, thus all found components will be deleted (without the 
>> removed) BUT we should delete all components associated with this 
>> Product instance.
> 
> 
> Mhh. The original semantics of auto-delete=true was to delete all items 
> that are contained in the collection. why should the PB delete instances 
> that are not in the collection anymore?
> 
Problem is when foreign key constraints defined in the DB.

>> 2. auto-retrieve is set false. Get a Product and delete it. Since we 
>> set auto-delete true we expect that all associated Components will be 
>> deleted too.
>>
> 
> This will also not work for the same reason.
> 
> I see where you are coming from. You want to have the same semantics as 
> with a database based cascading delete.
> 
yep, that was my interpretation of auto-delete (my misinterpretation;-)).

> I don't think the OJB behaviour is buggy. It simply works as designed.
now its clear!

> (I fear I'm sounding like Bill Gates now ;-))
If OJB will run on 75% of all PC in future it's ok to sound like Bill ;-)

> Maybe we should clearly state that auto-delete="true" is not equivalent 
> with a cascing delete in the database?
yes, please a clear explanation of all auto-xy attributes in the docs.

regards,
Armin

> 
> have a nice weekend,
> Thomas
> 
>> Or do I misinterpret the 'auto-delete' flag?
>>
>> regards,
>> Armin
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 



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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

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

Armin Waibel wrote:
> Hi all,
> 
> I think I found a bug? in PBImpl class on delete of the 1:n relations of 
> the main object when auto-delete is set true in metadata.
> 
> Say we have a Product class and a Component class, Product has a 1:n 
> relation to Component and we set auto-delete in collection-descriptor.
> 
> Product
> {
> id
> name
> components
> }
> 
> Component
> {
> id
> name
> productId
> }
> 
> 1. auto-retrieve is set true and we query a Product, then we get all 
> Components from Product and remove some components (or set components 
> 'null'). After this we delete this Product instance ---> auto-delete is 
> true, thus all found components will be deleted (without the removed) 
> BUT we should delete all components associated with this Product instance.

Mhh. The original semantics of auto-delete=true was to delete all items 
that are contained in the collection. why should the PB delete instances 
that are not in the collection anymore?

> 2. auto-retrieve is set false. Get a Product and delete it. Since we set 
> auto-delete true we expect that all associated Components will be 
> deleted too.
> 

This will also not work for the same reason.

I see where you are coming from. You want to have the same semantics as 
with a database based cascading delete.

I don't think the OJB behaviour is buggy. It simply works as designed.
(I fear I'm sounding like Bill Gates now ;-))

Maybe we should clearly state that auto-delete="true" is not equivalent 
with a cascing delete in the database?

have a nice weekend,
Thomas

> Or do I misinterpret the 'auto-delete' flag?
> 
> regards,
> Armin
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 


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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
>>>1. auto-retrieve is set true and we query a Product, then we get all
>>>Components from Product and remove some components (or set components
>>>'null'). After this we delete this Product instance ---> auto-delete is
>>>true, thus all found components will be deleted (without the removed)
>>>BUT we should delete all components associated with this Product
>>> instance.
>>
>> Here the problem we see is you have not enabled the auto-update
>> attribute.
>>
> In my test case auto-update is true, but I think that is irrelevant.
> I will check in the test case ASAP.
>
>> Why? Because if you set to null an item in the collection this does not
>> mean: "Delete" it is just an update of the item.
> yes, in my test case I remove some collection objects, e.g. two from
> five. But when I delete the main object (containing the collection) I
> expect that all five objects will be deleted when the main object is
> deleted. Currently only three objects will be deleted and I get an DB
> constraint exception.

When you set them to null or get them out of the list, then PB cannot
access them and this is why PB only remove the 3 knowed.

Auto-retrieve is not trigged before a delete since it would be a penality
and can cause other problem, when you are updating. So it is not sense to
trigg auto-retrieve just before the delete action.
>
>> The default behavior of
>> auto-update is false, so PB does not do this automatically. This is why
>> they remains our if you configured constrains in the database the remove
>> can also fail, because there will be some register not deleted (the once
>> you setted to null and need to update because you have not enable the
>> auto-update attribute.
>>
>> In order to avoid the use of auto-update, please get the item out of the
>> collection. I think in that way auto-delete will do the work fine.
>>
>>
>>>2. auto-retrieve is set false. Get a Product and delete it. Since we set
>>>auto-delete true we expect that all associated Components will be
>>>deleted too.
>>
>> Hmm. Problem here is that the collections items are not retrieved, so PB
>> is not aware of them. This is why they stay in the database.
>>
> yep, but I expect that all dependend objects will be deleted when I set
> auto-delete true (independent from the other auto-XX attributes), or we
> need a more exact description of these attributes in doc.

How can PB know about the items in the collections if we not retrieve them?

PB works with at Java Bean level (based on the info stored on the bean).
PB cannot and I think it is not desirable (because of performance
penality) to retrieve the object from DB, compare with the current bean
and guess what are we what to do.

And what if we really just need to delete 3 of the object because the
other we already need update or attach to another object. Currently, I
cannot provide an example of that, but it can be requiered in a case.

I think the attributes behavior is correct as it is now, as you suggested
maybe the docs can be improved a little. Also, maybe some examples, will
help here.

Best Regards,

Antonio Gallardo


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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Antonio,

Antonio Gallardo wrote:

> Hi Armin:
> 
> Third and (hope the last answer) :-D Sorry, but I think this is very
> important point and while I am trying to explain I am learnig too. I am
> reasoning this whith a friend while posting. Our view point are between
> lines:
Here my first attempt to answer ;-)

> 
> Armin Waibel dijo:
> 
>>Hi all,
>>
>>I think I found a bug? in PBImpl class on delete of the 1:n relations of
>>the main object when auto-delete is set true in metadata.
>>
>>Say we have a Product class and a Component class, Product has a 1:n
>>relation to Component and we set auto-delete in collection-descriptor.
>>
>>Product
>>{
>>id
>>name
>>components
>>}
>>
>>Component
>>{
>>id
>>name
>>productId
>>}
>>
>>1. auto-retrieve is set true and we query a Product, then we get all
>>Components from Product and remove some components (or set components
>>'null'). After this we delete this Product instance ---> auto-delete is
>>true, thus all found components will be deleted (without the removed)
>>BUT we should delete all components associated with this Product instance.
> 
> 
> Here the problem we see is you have not enabled the auto-update attribute.
> 
In my test case auto-update is true, but I think that is irrelevant.
I will check in the test case ASAP.

> Why? Because if you set to null an item in the collection this does not
> mean: "Delete" it is just an update of the item.
yes, in my test case I remove some collection objects, e.g. two from 
five. But when I delete the main object (containing the collection) I 
expect that all five objects will be deleted when the main object is 
deleted. Currently only three objects will be deleted and I get an DB 
constraint exception.

> The default behavior of
> auto-update is false, so PB does not do this automatically. This is why
> they remains our if you configured constrains in the database the remove
> can also fail, because there will be some register not deleted (the once
> you setted to null and need to update because you have not enable the
> auto-update attribute.
> 
> In order to avoid the use of auto-update, please get the item out of the
> collection. I think in that way auto-delete will do the work fine.
> 
> 
>>2. auto-retrieve is set false. Get a Product and delete it. Since we set
>>auto-delete true we expect that all associated Components will be
>>deleted too.
> 
> 
> Hmm. Problem here is that the collections items are not retrieved, so PB
> is not aware of them. This is why they stay in the database.
> 
yep, but I expect that all dependend objects will be deleted when I set 
auto-delete true (independent from the other auto-XX attributes), or we 
need a more exact description of these attributes in doc.

regards,
Armin

> 
>>Or do I misinterpret the 'auto-delete' flag?
> 
> 
> Best Regards,
> 
> Antonio Gallardo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 



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


Re: [Bug?] PBImpl delete of 1:n relation when auto-delete is set true

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Armin:

Third and (hope the last answer) :-D Sorry, but I think this is very
important point and while I am trying to explain I am learnig too. I am
reasoning this whith a friend while posting. Our view point are between
lines:

Armin Waibel dijo:
> Hi all,
>
> I think I found a bug? in PBImpl class on delete of the 1:n relations of
> the main object when auto-delete is set true in metadata.
>
> Say we have a Product class and a Component class, Product has a 1:n
> relation to Component and we set auto-delete in collection-descriptor.
>
> Product
> {
> id
> name
> components
> }
>
> Component
> {
> id
> name
> productId
> }
>
> 1. auto-retrieve is set true and we query a Product, then we get all
> Components from Product and remove some components (or set components
> 'null'). After this we delete this Product instance ---> auto-delete is
> true, thus all found components will be deleted (without the removed)
> BUT we should delete all components associated with this Product instance.

Here the problem we see is you have not enabled the auto-update attribute.

Why? Because if you set to null an item in the collection this does not
mean: "Delete" it is just an update of the item. The default behavior of
auto-update is false, so PB does not do this automatically. This is why
they remains our if you configured constrains in the database the remove
can also fail, because there will be some register not deleted (the once
you setted to null and need to update because you have not enable the
auto-update attribute.

In order to avoid the use of auto-update, please get the item out of the
collection. I think in that way auto-delete will do the work fine.

> 2. auto-retrieve is set false. Get a Product and delete it. Since we set
> auto-delete true we expect that all associated Components will be
> deleted too.

Hmm. Problem here is that the collections items are not retrieved, so PB
is not aware of them. This is why they stay in the database.

> Or do I misinterpret the 'auto-delete' flag?

Best Regards,

Antonio Gallardo

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