Re: PersistenceBroker.deleteByQuery(QueryByCriteria q) does not delete objects referenced by a collection-descriptor?

Danilo Tommasina <[email protected]> Fri, 14 Dec 2007 10:53:23 +0100
Newsgroups gmane.comp.jakarta.ojb.user
Organization RCS AG
Message-ID <[email protected]>
Hi Alessandro,

when I started to use OJB I wrote a custom deleteByQuery(...) override that was also cleaning up the cache, I simply did a SELECT with the same query used for 
the DELETE, applied the DELETE statement and removed all objects from cache returned by the SELECT. Since we are never using the deleteByQuery(..) in our 
product, at some point I removed the code above.
The deleteByQuery(...) simply forwards the DELETE statement to the database without applying any auto-xxx settings nor cleaning up the cache. It is performant 
for bulk-deletion, but leaves the cache in an inconsistent status and is not consistent with the auto-xxx settings.

It is currently not possbile to use delete( obj ) where obj is a template.

bye
danilo

Alessandro Colantoni wrote:
> Hi,
> 
> really deleteByQuery does not check on auto-delete settings??
> I always used broker.delete(Object pInstance), and it feels the auto-delete
> settings and removes the deleted instance from the cache.
> Or at the least this is the behavior I always saw.
> 
> Anyway if the   deleteByQuery do not feel the autodelete ="true" why Danilo
> does not get the FK integerity violation (I think he has an 1:n mapping)?
> 
> I was thinking to write some method using the deletebyquery, but I won't if
> I can't use the auto-delete and I have problem with cache.
> 
> Can I use delete(Object pInstance) where pInstance is a template?
> for example suppose I have a class Car, with attribute, (constructor,
> engine, color, seatNumber....)
> 
> If I do
> Car car = new Car()
> car.setColor("red")
> broker.delete(car);
> 
> will be deleted all red cars? or what kind of behavior have I to expect.
> 
> Thanks
> Alessandro
> 
> 
> On 12/13/07, Danilo Tommasina <[email protected]> wrote:
>> Hi,
>>
>> iirc the deleteByQuery(...) method, just produces SQL that is forwarded to
>> the database directly without any check on auto-delete settings. This method
>> does not
>> even remove deleted objects from cache.
>>
>> Regards
>> danilo
>>
>> Hiller, Frank RD-PT31 wrote:
>>> Hi,
>>>
>>> no, I don't get an error.
>>> When using "PersistenceBroker.deleteByQuery(QueryByCriteria q)" the
>>> "parent" object is deleted, not the referenced objects.
>>> I didn't check the OJB code, but I guess this is normal behaviour for
>>> "deleteByQuery".
>>>
>>> When I read the object first with
>>> "PersistenceBroker.getObjectByQuery(QueryByCriteria q)" and delete the
>>> received object everything is fine.
>>>
>>> Best regards.............Frank
>>>
>>> -----Original Message-----
>>> From: Alessandro Colantoni [mailto:[email protected]]
>>> Sent: Thursday, December 13, 2007 12:35 PM
>>> To: OJB Users List
>>> Subject: Re: PersistenceBroker.deleteByQuery(QueryByCriteria q) does not
>>> delete objects referenced by a collection-descriptor?
>>>
>>> Hi,
>>> right, and if it is not deleted you could get run time error due to the
>>> FK .
>>> Anyway it is better you set the auto-delete to "object", that is the
>>> same, but "true" and "false" are deprecated .
>>>
>>> Best regards
>>> Alessandro
>>>
>>> On 12/13/07, Hiller, Frank RD-PT31 <[email protected]> wrote:
>>>> Hi Alessandro,
>>>>
>>>> thank you for the quick response.
>>>>
>>>> auto-delete is set to "true".
>>>>
>>>> Otherwise "PersistenceBroker.delete(obj)" wouldn't delete the
>>>> referenced collections either.
>>>>
>>>> Best regards.............Frank
>>>>
>>>> -----Original Message-----
>>>> From: Alessandro Colantoni [mailto:[email protected]]
>>>> Sent: Thursday, December 13, 2007 11:53 AM
>>>> To: OJB Users List
>>>> Subject: Re: PersistenceBroker.deleteByQuery(QueryByCriteria q) does
>>>> not delete objects referenced by a collection-descriptor?
>>>>
>>>> Hi,
>>>>
>>>> it depends on the auto-delete settings:
>>>>
>>>> http://db.apache.org/ojb/docu/guides/basic-technique.html#1%3A1+auto-x
>>>> xx
>>>> +setting
>>>>
>>>> http://db.apache.org/ojb/docu/guides/basic-technique.html#1%3An+auto-x
>>>> xx
>>>> +setting
>>>>
>>>> http://db.apache.org/ojb/docu/guides/basic-technique.html#m%3An+auto-x
>>>> xx
>>>> +setting
>>>>
>>>>
>>>> regards
>>>> Alessandro
>>>>
>>>>
>>>>
>>>> On 12/13/07, Hiller, Frank RD-PT31 <[email protected]>
>>> wrote:
>>>>> Hi community,
>>>>>
>>>>> I'm using PersistenceBroker of OJB1.0.3.
>>>>>
>>>>> Is it correct that "PersistenceBroker.deleteByQuery(QueryByCriteria
>>>> q)"
>>>>> does not delete objects referenced by a collection-descriptor?
>>>>>
>>>>> Whene I use
>>>>> (1) Object obj = PersistenceBroker.getObjectByQuery(QueryByCriteria
>>>>> q)
>>>>> (2) PersistenceBroker.delete(obj)
>>>>>
>>>>> it works.
>>>>>
>>>>> Thanks
>>>>> Frank
>>>>>
>>>>>
>>>>> Confidentiality note:
>>>>> The information in this email and any attachment may contain
>>>>> confidential and proprietary information of Heidelberger
>>>>> Druckmaschinen AG and/or its affiliates and may be privileged or
>>>>> otherwise protected from disclosure. If you are not the intended
>>>>> recipient, you are hereby notified that any review, reliance or
>>>>> distribution by others or forwarding without express permission is
>>>>> strictly prohibited and may cause liability. In case you have
>>>>> received
>>>>> this message due to an error in transmission, we kindly ask you to
>>>>> notify the sender immediately and to delete this email and any
>>>> attachment from your system.
>>>>
>>>> Confidentiality note:
>>>> The information in this email and any attachment may contain
>>>> confidential and proprietary information of Heidelberger
>>>> Druckmaschinen AG and/or its affiliates and may be privileged or
>>>> otherwise protected from disclosure. If you are not the intended
>>>> recipient, you are hereby notified that any review, reliance or
>>>> distribution by others or forwarding without express permission is
>>>> strictly prohibited and may cause liability. In case you have received
>>>> this message due to an error in transmission, we kindly ask you to
>>>> notify the sender immediately and to delete this email and any
>>> attachment from your system.
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>>
>>>>
>>>
>>> Confidentiality note:
>>> The information in this email and any attachment may contain
>> confidential and proprietary information of Heidelberger Druckmaschinen AG
>> and/or its affiliates and may be privileged or otherwise protected from
>> disclosure. If you are not the intended recipient, you are hereby notified
>> that any review, reliance or distribution by others or forwarding without
>> express permission is strictly prohibited and may cause liability. In case
>> you have received this message due to an error in transmission, we kindly
>> ask you to notify the sender immediately and to delete this email and any
>> attachment from your system.
>>> ---------------------------------------------------------------------
>>> 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]
>>
>>
>