> Hope this helps.
Yep, it makes sense.
/keld
----- Original Message -----
From: "Patrick van Kann" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 17, 2003 10:52 AM
Subject: Re: [castor-dev] Handling your relations in Castor-JDO
> Generally Castor expects relationships to be bi-directional and that you
> should manage this yourself by ensuring that the set method of the child
> calls the add/set method of the parent when the relationship is created.
> The examples show how this works.
>
> However, the bi-directionality is not enforced in all cases. I cannot
> make a simple statement of the exceptions as I don't exactly know. It is
> safest to simply make all relationships bi-directional.
>
> In answer your question the procedure for changing a parent should be:
> Load child (and thereby the parent automaticallly)
> Load the new parent in the same transaction.
> Destroy the relationship between child and current parent - this may be
> as simple as calling
> oldPublisher.removeBook ( book );
> newPublisher.addBook ( book );
> book.setPublisher( newPublisher );
>
> Then commit the transaction.
>
> Hope this helps.
>
> Patrick
>
> Keld Helbig Hansen wrote:
>
> >I've got a general question about the working of Castor-JDO:
> >
> >Say we have a many-to-one relation e.g. "books" to "publisher".
> >This means I have a Book and a Publisher class, Book has a property of type
> >Publisher, and Publisher has a property of type Collection (of Book).
> >
> >"Book1" has publisher "O'Reilly" and I now change this to another publisher - say
> >"Wrox" - the code goes like this (sketched):
> >
> > db.begin();
> > Book b = (Book)db.load(Book.class, new Integer(1));
> > Publisher p2 = (Publisher)db.load(Publisher.class, new Integer(2));
> > b.setPublisher(p2);
> > db.commit();
> > db.close();
> >
> >As you can see I've NOT removed "Book1" from "O'Reilly" nor have I added it to
> >"Wrox".
> >The question is now if I should do this?
> >If I in the example (after db.commit and db.close) ) look into the Collection (of
> >Book) from the "O'Reilly" instance what do I find?
> >Answer is (I tried it!): "Book1" has been removed!
> >How can this be? Who removed it???
> >
> >Next question:
> >If I take the Collection (of Book) from the "Wrox" instance what do I find?
> >Answer is : "Book1" has NOT been added.
> >???
> >
> >This leads to a more general question: when you're working with relations between
> >your objects and you change a relation between two objects, is it then necessary to
> >keep the integrity of you objects by adding and removing to the Collection's in
> >both ends - or does castor help you in some situations? As I noticed in the example
> >above.
> >
> >I'd be grateful for any hints on this.
> >
> >/Keld
> >
> >-----------------------------------------------------------
> >If you wish to unsubscribe from this mailing, send mail to
> >[EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
> >
> >
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev