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