Hi Olli 

I am using the ODMG API.

When I wish to "edit" an object that contains a collection (representing my
1->n relationship); if I add or remove any objects from the collection I
must call either makePersistent or deletePersistent for each of those
objects.  

It would be nice to be able to add and remove the objects from the
collection, persist the object holding the collection (the '1' in the
1->n)and have the state of each object in the collection reflected in the
database automatically.  It does this when the object is persisted for the
first time.

This is what I would have thought would naturally happen but as it does not
I was wondering if there is some other logical reason as to why it does not?

Cheers
Shane

-----Original Message-----
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: 17/06/2003 6:22 p.m.
Subject: RE: how to update a collection reference

Hello Shane,

> -----Original Message-----
> From: Shane Mingins [mailto:[EMAIL PROTECTED]


> If OJB is meant to provide the persistence mechanism for my 
> application so
> that I can then just code against Objects, why shouldn't I 
> expect to be able
> to persist an Object that holds a collection of other Objects 
> (1->n) and
> have the state of my Object reflected in the persistence 
> operation without
> micro-managing the 'n' side of the relationship?

OJB can do this for you.  When I wrote "Why would you expect that to
happen?"
I was referring to your expectation that objects get removed from
the database when you remove them from a particular collection.
This is not was I would expect.  (But I think even that
is possible with the 'RemovalAwareCollection').

> It seems that the original persistence of the Object supports our
> expectations but subsequent operations do not.

May I ask which API you use?  The ODMG API contains more 
magic, so might be more happy with it than with the 
PersistenecBroker API. 

If you use the PB API nevertheless, you might try to set 
auto-update attribute in the collection-descriptor to true,
it might do what you want.
There are some other attributes that control the behaviour
of references and collections.  See
http://db.apache.org/ojb/repository.html
for details.

> > My problem is that the objects B I remove from the list of 
> > objects B are not deleted in the database when I update the 
> object A.
> 
> Why would you expect that to happen? When you wish to delete an
> item b from the database, you have to explicitly delete it with the
> suitable API call, e.g.
>       broker.delete(x);  // PersistenceBroker
> or
>       database.deletePersistent(x);  // ODMG

Olli

---------------------------------------------------------------------
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]

Reply via email to