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 "Dirk Manske (Service Respond)" <se...@nexgo.de> on 2004/02/16 13:27:30 UTC

Delete object in a 1:N assoc only with RemovalAwareCollection?

Hi,

I am using PB API with DB2. I experience the phenomen that in a 1:N
association a N object is not being deleted. I do not use a
RemovalAwareCollection. Here is the scenario:

Table Activity and table Schedule are 1:N related. A user can delete a
specific schedule or all schedules of a particular activity object. If the
user selects a schedule to delete, the app retrieves the scheduleId and
scheduleObject from the DB. Then it simply deletes the object by
broker.delete(scheduleObject). So far it is only theory because the
scheduleObject remains in the DB. How to delete?

I could not find anything in the faqs. However, the testcases always use
RemovalAwareCollection. Can someone point out the concept behind this?

thx,
Dirk


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


Re: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Armin Waibel <ar...@apache.org>.
Hi Rainer,

Rainer Klute wrote:
...
>>hmm, you can use non-distributed ObjectCache implementation, e.g. 
>>ObjectCachePerBrokerImpl. This supports circular references and avoid 
>>concurrent object modification by other threads/broker instances.
>>But you will loose all cached objects when broker was closed/rolled back.
>>Nevertheless, if you have a fast DB and a fast network between OJB and 
>>DB this should be ok.
> 
> 
> I tried the ObjectCachePerBrokerImpl but unfortunately lost the circular references.
> 

hmm, this implementation does support circular references. Think there 
is something going wrong in your app, e.g. different threads using same 
PB instance.

> 
> Okay, folks, thanks for your time and effort and good luck with
forthcoming OJB versions! I'll keep an eye on its development - but just 
not now.
>

Thanks for give it a try.

regards,
Armin

> 
> Best regards
> Rainer Klute
> 
>                            Rainer Klute IT-Consulting GmbH
>   Dipl.-Inform.
>   Rainer Klute             E-Mail:  klute@rainer-klute.de
>   Körner Grund 24          Telefon: +49 172 2324824
> D-44143 Dortmund           Telefax: +49 231 5349423
> 
> ---------------------------------------------------------------------
> 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: Query on collection descriptors

Posted by Armin Waibel <ar...@apache.org>.
Hi Raghavan,

Kollivakkam R. Raghavan wrote:

> If I have a 1-n relationship between two entities represented as a
> collection-descriptor in OJB, how can I use the PB Query API to retrieve
> items in the collections based on some constraint on the n side of the
> relationship.  In other words I don't want to get all the entries in the
> collection but only the ones that satisfy the constraint.
> 

you can try to implement a QueryCustomizer
http://db.apache.org/ojb/tutorial3.html#Customizing collection queries

regards,
Armin

> For example:
> If I had a classroom table and a student table which has a 1-n
> relationship (each classroom has n students male or female), I want to
> write a PB query that returns me all male (or female) students in a
> given classroom (assume that gender is an attribute in the student
> table).  Is this possible?
> 
> Thanks in advance
> Raghavan
> 
> 
> ---------------------------------------------------------------------
> 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


Query on collection descriptors

Posted by "Kollivakkam R. Raghavan" <rk...@cisco.com>.
If I have a 1-n relationship between two entities represented as a
collection-descriptor in OJB, how can I use the PB Query API to retrieve
items in the collections based on some constraint on the n side of the
relationship.  In other words I don't want to get all the entries in the
collection but only the ones that satisfy the constraint.

For example:
If I had a classroom table and a student table which has a 1-n
relationship (each classroom has n students male or female), I want to
write a PB query that returns me all male (or female) students in a
given classroom (assume that gender is an attribute in the student
table).  Is this possible?

Thanks in advance
Raghavan


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


Re: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Rainer Klute <kl...@rainer-klute.de>.
On Sat, 21 Feb 2004 16:02:54 +0100 Armin Waibel <ar...@apache.org> wrote:
> "something working the next days", puh!

Nobody expects you to implement this "the next days" in OJB. This is a volunteer effort, anyway. It is just me who needs a working application, whether it is based on OJB or not.


> This is exactly what we want for 1.1. We have to introduce a real 
> two-level cache.
> On first level we temporary buffer objects to resolve circular 
> references, on second level we cache copies of objects without their 
> references. This is nothing to make work in a few days ;-)
> In CVS you can find a ObjectCache (alpha-)implementation by Oliver Matz 
> called TwoLevelCache which try to bypass current cache problems (but 
> cause new problems).

Well, since I am under tight time pressure I am not free for any experiment that might fail. For my concrete project I decided to do it The Hard Way, junk OJB and implement everything with direct JDBC calls. This is not elegant, leaves room for bugs but it does work and I have full control over what happens. And since I have only a handfull of classes and a rather simple data model, switching to JDBC wasn't too hard.

I'd might get back to OJB later with other projects, though.


> hmm, you can use non-distributed ObjectCache implementation, e.g. 
> ObjectCachePerBrokerImpl. This supports circular references and avoid 
> concurrent object modification by other threads/broker instances.
> But you will loose all cached objects when broker was closed/rolled back.
> Nevertheless, if you have a fast DB and a fast network between OJB and 
> DB this should be ok.

I tried the ObjectCachePerBrokerImpl but unfortunately lost the circular references.


> Or before start to modify make a deep copy of the object (e.g. introduce 
> a CopyFactory or something similar), then lock the copy and start to modify.

That's just what I wanted to avoid. I'd like to retrieve an object from the DB, modify it and then either persist the modifications or throw them away.


Okay, folks, thanks for your time and effort and good luck with forthcoming OJB versions! I'll keep an eye on its development - but just not now.


Best regards
Rainer Klute

                           Rainer Klute IT-Consulting GmbH
  Dipl.-Inform.
  Rainer Klute             E-Mail:  klute@rainer-klute.de
  Körner Grund 24          Telefon: +49 172 2324824
D-44143 Dortmund           Telefax: +49 231 5349423

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


Re: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Armin Waibel <ar...@apache.org>.
Hi Rainer,

Rainer Klute wrote:


> this is good news! However, I need something working the next days that supports circular
references and lets modifications of persistent objects to be ignored if 
these objects are
not locked in a ODMG transaction.
> 

"something working the next days", puh!
This is exactly what we want for 1.1. We have to introduce a real 
two-level cache.
On first level we temporary buffer objects to resolve circular 
references, on second level we cache copies of objects without their 
references. This is nothing to make work in a few days ;-)
In CVS you can find a ObjectCache (alpha-)implementation by Oliver Matz 
called TwoLevelCache which try to bypass current cache problems (but 
cause new problems).

> Do you have an idea to do this right? Presently I am thinking about copying a whole graph
of persistent objects to an equivalent graph of non-persistent ones. The 
latter I can modify
at will without consequences to the database or to the cache. However, 
if I decide to persist
them I have a) to delete the object tree from the DB (and from the 
cache) and b) make my
non-persistent tree persistent. This is one big hack with all sorts of 
pitfalls and I'd
like to know if there's a better approach.
> 

hmm, you can use non-distributed ObjectCache implementation, e.g. 
ObjectCachePerBrokerImpl. This supports circular references and avoid 
concurrent object modification by other threads/broker instances.
But you will loose all cached objects when broker was closed/rolled back.
Nevertheless, if you have a fast DB and a fast network between OJB and 
DB this should be ok.

Or before start to modify make a deep copy of the object (e.g. introduce 
a CopyFactory or something similar), then lock the copy and start to modify.

regards,
Armin

> Best regard
> Rainer Klute
> 
>                            Rainer Klute IT-Consulting GmbH
>   Dipl.-Inform.
>   Rainer Klute             E-Mail:  klute@rainer-klute.de
>   Körner Grund 24          Telefon: +49 172 2324824
> D-44143 Dortmund           Telefax: +49 231 5349423
> 
> ---------------------------------------------------------------------
> 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: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Rainer Klute <kl...@rainer-klute.de>.
On Sat, 21 Feb 2004 14:21:55 +0100 Armin Waibel <ar...@apache.org> wrote:
> > The behaviour should be independend of any cache, i.e. an application
> should always behave the same whether there is a cache or not and whatever
> cache implementation is used.
> > 
> > Unfortunately this is not the case. Are there any chances to have
> this changed? I am willing to invest some effort if the committers
> regard this as a reasonable development target.
> > 
> 
> This is one main topic for OJB 1.1 version. Currently OJB use the 
> ObjectCache to resolve circular references. In 1.1 we will introduce and 
> new internal level that will resolve this independed from the used 
> ObjectCache.

Hi Armin,

this is good news! However, I need something working the next days that supports circular references and lets modifications of persistent objects to be ignored if these objects are not locked in a ODMG transaction.

Do you have an idea to do this right? Presently I am thinking about copying a whole graph of persistent objects to an equivalent graph of non-persistent ones. The latter I can modify at will without consequences to the database or to the cache. However, if I decide to persist them I have a) to delete the object tree from the DB (and from the cache) and b) make my non-persistent tree persistent. This is one big hack with all sorts of pitfalls and I'd like to know if there's a better approach.

Best regard
Rainer Klute

                           Rainer Klute IT-Consulting GmbH
  Dipl.-Inform.
  Rainer Klute             E-Mail:  klute@rainer-klute.de
  Körner Grund 24          Telefon: +49 172 2324824
D-44143 Dortmund           Telefax: +49 231 5349423

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


Re: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Armin Waibel <ar...@apache.org>.
Hi Rainer,

Rainer Klute wrote:

> On Sat, 21 Feb 2004 13:48:29 +0100 "Dirk Manske (Service Respond)" <se...@nexgo.de> wrote:
> 
>>problem is solved. I do a broker.clearCache after an object has been deleted
>>and changed the auto-update setting to false. But I guess this is not an
>>expected behaviour that the object remains in cache after it has been
>>deleted, does it? Or in general, should one always do a clearCache after
>>update, insert or delete?
> 
> 
> The behaviour should be independend of any cache, i.e. an application
should always behave the same whether there is a cache or not and whatever
cache implementation is used.
> 
> Unfortunately this is not the case. Are there any chances to have
this changed? I am willing to invest some effort if the committers
regard this as a reasonable development target.
> 

This is one main topic for OJB 1.1 version. Currently OJB use the 
ObjectCache to resolve circular references. In 1.1 we will introduce and 
new internal level that will resolve this independed from the used 
ObjectCache.

Any help, proposals are welcome!

regards,
Armin

> Best regards
> Rainer Klute
> 
>                            Rainer Klute IT-Consulting GmbH
>   Dipl.-Inform.
>   Rainer Klute             E-Mail:  klute@rainer-klute.de
>   Körner Grund 24          Telefon: +49 172 2324824
> D-44143 Dortmund           Telefax: +49 231 5349423
> 
> ---------------------------------------------------------------------
> 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: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Rainer Klute <kl...@rainer-klute.de>.
On Sat, 21 Feb 2004 13:48:29 +0100 "Dirk Manske (Service Respond)" <se...@nexgo.de> wrote:
> problem is solved. I do a broker.clearCache after an object has been deleted
> and changed the auto-update setting to false. But I guess this is not an
> expected behaviour that the object remains in cache after it has been
> deleted, does it? Or in general, should one always do a clearCache after
> update, insert or delete?

The behaviour should be independend of any cache, i.e. an application should always behave the same whether there is a cache or not and whatever cache implementation is used.

Unfortunately this is not the case. Are there any chances to have this changed? I am willing to invest some effort if the committers regard this as a reasonable development target.

Best regards
Rainer Klute

                           Rainer Klute IT-Consulting GmbH
  Dipl.-Inform.
  Rainer Klute             E-Mail:  klute@rainer-klute.de
  Körner Grund 24          Telefon: +49 172 2324824
D-44143 Dortmund           Telefax: +49 231 5349423

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


Re: AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Armin Waibel <ar...@apache.org>.
Hi Dirk,

Dirk Manske (Service Respond) wrote:

> Hi Armin,
> 
> problem is solved. I do a broker.clearCache after an object has been deleted
> and changed the auto-update setting to false. But I guess this is not an
> expected behaviour that the object remains in cache after it has been
> deleted, does it? Or in general, should one always do a clearCache after
> update, insert or delete?
> 

When delete an object, OJB remove it from cache automatic, so it is not 
necessary to clear the cache. But it is possible that the deleted object 
is still part of an collection of another object and could be inserted 
again when store this object (if you don't care). Except when using 
PB.deleteByQuery(...), here we have an open issue (and lack of docu).

regards,
Armin

> Dirk   
> 
> -----Ursprüngliche Nachricht-----
> Von: Armin Waibel [mailto:arminw@apache.org] 
> Gesendet: Samstag, 21. Februar 2004 13:36
> An: OJB Users List
> Betreff: Re: Delete object in a 1:N assoc only with RemovalAwareCollection?
> 
> Hi Dirk,
> 
> Dirk Manske (Service Respond) wrote:
> 
>>Hi,
>>
>>I am using PB API with DB2. I experience the phenomen that in a 1:N 
>>association a N object is not being deleted. I do not use a 
>>RemovalAwareCollection. Here is the scenario:
>>
>>Table Activity and table Schedule are 1:N related. A user can delete a 
>>specific schedule or all schedules of a particular activity object. If 
>>the user selects a schedule to delete, the app retrieves the 
>>scheduleId and scheduleObject from the DB. Then it simply deletes the 
>>object by broker.delete(scheduleObject). So far it is only theory 
>>because the scheduleObject remains in the DB. How to delete?
>>
> 
> 
> hmm, sounds strange. Are your sure that the schedule object wasn't deleted
> from DB, or did OJB find this object in cache after delete?
> Do you store the Activity object after the delete too and set auto-update
> true in collection-descriptor of Activity and do not remove (the deleted)
> schedule object from collection?
> 
> 
> regards,
> Armin
> 
> 
>>I could not find anything in the faqs. However, the testcases always 
>>use RemovalAwareCollection. Can someone point out the concept behind this?
>>
>>thx,
>>Dirk
>>
>>
>>---------------------------------------------------------------------
>>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
> 
> 
> 

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


AW: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by "Dirk Manske (Service Respond)" <se...@nexgo.de>.
Hi Armin,

problem is solved. I do a broker.clearCache after an object has been deleted
and changed the auto-update setting to false. But I guess this is not an
expected behaviour that the object remains in cache after it has been
deleted, does it? Or in general, should one always do a clearCache after
update, insert or delete?

Dirk   

-----Ursprüngliche Nachricht-----
Von: Armin Waibel [mailto:arminw@apache.org] 
Gesendet: Samstag, 21. Februar 2004 13:36
An: OJB Users List
Betreff: Re: Delete object in a 1:N assoc only with RemovalAwareCollection?

Hi Dirk,

Dirk Manske (Service Respond) wrote:
> Hi,
> 
> I am using PB API with DB2. I experience the phenomen that in a 1:N 
> association a N object is not being deleted. I do not use a 
> RemovalAwareCollection. Here is the scenario:
> 
> Table Activity and table Schedule are 1:N related. A user can delete a 
> specific schedule or all schedules of a particular activity object. If 
> the user selects a schedule to delete, the app retrieves the 
> scheduleId and scheduleObject from the DB. Then it simply deletes the 
> object by broker.delete(scheduleObject). So far it is only theory 
> because the scheduleObject remains in the DB. How to delete?
>

hmm, sounds strange. Are your sure that the schedule object wasn't deleted
from DB, or did OJB find this object in cache after delete?
Do you store the Activity object after the delete too and set auto-update
true in collection-descriptor of Activity and do not remove (the deleted)
schedule object from collection?


regards,
Armin

> I could not find anything in the faqs. However, the testcases always 
> use RemovalAwareCollection. Can someone point out the concept behind this?
> 
> thx,
> Dirk
> 
> 
> ---------------------------------------------------------------------
> 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: Delete object in a 1:N assoc only with RemovalAwareCollection?

Posted by Armin Waibel <ar...@apache.org>.
Hi Dirk,

Dirk Manske (Service Respond) wrote:
> Hi,
> 
> I am using PB API with DB2. I experience the phenomen that in a 1:N
> association a N object is not being deleted. I do not use a
> RemovalAwareCollection. Here is the scenario:
> 
> Table Activity and table Schedule are 1:N related. A user can delete a
> specific schedule or all schedules of a particular activity object. If the
> user selects a schedule to delete, the app retrieves the scheduleId and
> scheduleObject from the DB. Then it simply deletes the object by
> broker.delete(scheduleObject). So far it is only theory because the
> scheduleObject remains in the DB. How to delete?
>

hmm, sounds strange. Are your sure that the schedule object wasn't 
deleted from DB, or did OJB find this object in cache after delete?
Do you store the Activity object after the delete too and set 
auto-update true in collection-descriptor of Activity and do not remove 
(the deleted) schedule object from collection?


regards,
Armin

> I could not find anything in the faqs. However, the testcases always use
> RemovalAwareCollection. Can someone point out the concept behind this?
> 
> thx,
> Dirk
> 
> 
> ---------------------------------------------------------------------
> 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