----- Original Message -----
From: "Armin Waibel" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Friday, January 09, 2004 10:32 AM
Subject: Re: ODMG Update Collection Problem
> Hi,
>
> Ralf Geiger wrote:
> > Hi,
> >
> > According to the mailing list I know that lots of people have similar
problems...but there is no real solution for it. For me OJB works fine..
except one thing: Updating a 1:N Collection of Elements.
> > I am using OJB RC5 ODMG-API with mySQL
> >
> > My Problem:
> >
> > I am having a 1:N relationship between A and B.
> > So A has a Collection of Bs.
> > B has one id which is the foreign-key (aid) and a reference to the
A-Object where B belongs to (refToA).
> >
> > Updating B works fine like this:
> >
> > tx.begin()
> > // Get newA from DB using PersistenceBroker
> > toBeSavedA.setAid( newA.getAid() );
> > tobeSavedA.setRefToA( newA );
> > tx.commit();
> >
> > So now the Problem is updating the Collection of B-Objects
> > Lets say a1 has already 2 B-Objects within the collection (b1 and b2):
> > Now I want to update the Collection and put the Objects (b3 and b4) into
it - b3 and b4 are already existing in the DB just belong to a2.
> > The situation:
> > a1{b1,b2}, a2{b3,b4} ---> a1{b3,b4}, a2{}, (b1 and b2 have null
references to any A-Object)
> >
>
> Do you lookup a1, a2 via PB-api too? If so, do you lock them before
> starting your modification?
>
> regards,
> Armin
>
Yeah, every Object I have has been loaded via PB-API.
My Applicationflow looks like this (web-application using Struts, running in
Tomcat):
1. Action: using PB-API to get all A-Objects and put them into Session-Scope
2. JSP: Show all A-Objects and referenced Bs.. just to see which Bs are
pointing to which a.
3. User Interaction: Edit a1
4. EditAction: using PB-API to get all possible B-Objects so that the User
can define which B-Objects he wants.
5. JSP: Show a1 and a List of B-Objects where he can choose... Let's say he
chose the b3 and b4
6. SaveAction: I get the Object a1 (toBeSaved), the b3 and b4 from the DB
(PB-API) (could have got it from the session-scope bean as well )
7. Now I begin the transaction and lock the toBeSaved-Object...
8. make the changes and commit..
that's all..
regards,
Ralf
> > If I am not mistaken the steps OJB takes should look like this:
> >
> > 1. Delete the references of b1 (aid=null and refToA=null) and b2 which
are pointing to a1
> > 2. Update the references of b3 and b4 so that they point to a1.
> > 3. Update the Collection of a2 because b3 and b4 are not in the
collection of a2 anymore.
> > 4 Update the Collection of a1: delete the references to b1 and b2 and
fill the collection with b3 and b4.
> > commit;
> >
> > I tried several Collections (java.util.Vector, ManageableVector,
ManageableArrayList, DListImpl)
> > but nothing works.
> > basically it for me it looks like this:
> >
> > tx.begin()
> > // Get the Collection of new Bs with
PersistenceBroker.getCollectionByQuery(B.class, crit) so I get this
Collection: newColOfB{b3,b4}
> > // Get the Collection of a1:
> > ManageableArrayList list = a1.getColOfB();
> >
> > // now update the list:
> > list.retainAll( newColOfB );
> >
> > tx.commit();
> >
> > But nothing has been updated in the DB..
> >
> > What is it ?? Can somebody please point out how to solve this problem ?
I really lost my nerves. Do I really have to update all references by
myselfe ??
> > Or am I just too stupid ? It works fine with m:n relationships.. just
setting the new collection..
> >
> > Thanks for your help,
> >
> > Ralf Geiger
> >
>
>
>
> ---------------------------------------------------------------------
> 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]