db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Weaver, Scott" <Swea...@rippe.com>
Subject RE: Update problems with ODMG and 1:N
Date Wed, 02 Jul 2003 18:51:55 GMT
This works for me:

// 1. Start the transaction

TransactionImpl tx = (TransactionImpl) odmg.newTransaction();

// 2. remove object from the OJB cache			
   
PersistenceBroker pb = tx.getBroker();
pb.removeFromCache(object);

tx.begin();

// 3. retreive a "stale" version of this object from the db

Identity id = new Identity(object, pb);
Object staleObject = 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();



*===================================*
* Scott T Weaver                    *
* Jakarta Jetspeed Portal Project   *
* weaver@apache.org                 *
*===================================*
  


> -----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
> 
> 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:
> 
> ...
> 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.
> 
> Then I tried:
> ...
> public void update( User user) {
> ...
> //Get the user from the database code as toBeEdited
> ...
> toBeEdited.getRoles().clear();
> Iterator iterator = user.getRoles().iterator();
> while( iterator.hasNext()) {
>   toBeEdited.getRoles().add( iterator.next());
> }
> 
> tx.commit();
> ...
> }
> 
> 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?
> 
> Or is there a better way to do what I want?
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message