Return-Path: Mailing-List: contact ojb-user-help@db.apache.org; run by ezmlm Delivered-To: mailing list ojb-user@db.apache.org Received: (qmail 95428 invoked from network); 2 Jul 2003 18:45:46 -0000 Received: from winexch02.int.rippe.com (HELO winexch02.rippe) (216.68.253.32) by daedalus.apache.org with SMTP; 2 Jul 2003 18:45:46 -0000 Received: by winexch02.rippe.com with Internet Mail Service (5.5.2653.19) id <31D2CJQS>; Wed, 2 Jul 2003 14:51:57 -0400 Message-ID: From: "Weaver, Scott" To: 'OJB Users List' Subject: RE: Update problems with ODMG and 1:N Date: Wed, 2 Jul 2003 14:51:55 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C340CB.02675110" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_001_01C340CB.02675110 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable This works for me: // 1. Start the transaction TransactionImpl tx =3D (TransactionImpl) odmg.newTransaction(); // 2. remove object from the OJB cache =09 =20 PersistenceBroker pb =3D tx.getBroker(); pb.removeFromCache(object); tx.begin(); // 3. retreive a "stale" version of this object from the db Identity id =3D new Identity(object, pb); Object staleObject =3D pb.getObjectByIdentity(id); tx.lock(staleObject, Transaction.WRITE); // 4. Map new values to the stale object BeanUtils.copyProperties(staleObject, object); // 5. Commit the transaction tx.commit(); *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D* * Scott T = Weaver=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 * * Jakarta Jetspeed Portal Project=A0=A0 * * weaver@apache.org=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 * *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D* =A0=20 > -----Original Message----- > From: Grim Shieldsson [mailto:grimshieldsson@yahoo.com] > Sent: Tuesday, July 01, 2003 7:06 PM > To: ojb-user@db.apache.org > Subject: Update problems with ODMG and 1:N >=20 > I'm writing a web application, and trying to get users and roles in = the > database. So I have a User and Role table/objects, where of course A > user can have multple roles. > I decided that I really didn't want to have the web page modifying = the > user/role objects inside a transaction, since this is a web > application. So I get the user info, find out what modifications to > the roles list they want, and then make the modifications. > So my update method looks like this: >=20 > ... > public void update( User user) { > ... > //Get the user from the database code as toBeEdited > ... > toBeEdited.setRoles( user.getRoles); > tx.commit(); > ... > } > Roles are DLists, however the DB does not get updated. >=20 > Then I tried: > ... > public void update( User user) { > ... > //Get the user from the database code as toBeEdited > ... > toBeEdited.getRoles().clear(); > Iterator iterator =3D user.getRoles().iterator(); > while( iterator.hasNext()) { > toBeEdited.getRoles().add( iterator.next()); > } >=20 > tx.commit(); > ... > } >=20 > But that doesn't work either. Oddly enough using just the clear > doesn't work either. Clear empties the DList, but does NOT do = anything > to the database. > I then tried to individually remove each role, and then add the new > ones back. No luck there either. > I'm trying to avoid having to do some sort of synchronizing between = the > two different roles. I'd like to just be able to delete the old = roles, > and add the new ones in it's place.... any ideas? >=20 > Or is there a better way to do what I want? >=20 >=20 >=20 > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org > For additional commands, e-mail: ojb-user-help@db.apache.org ------_=_NextPart_001_01C340CB.02675110--