About my previous auto-xxx mail:

When I say it "works perfect" I mean that changes are persisted.

On Thu, 2004-10-07 at 18:50, Martin I. Levi wrote:
> On Wed, 2004-10-06 at 17:30, Armin Waibel wrote:
> > Hi Martin,
> > 
> >  > If I get an A object (always through ODMG) from the DB, change the field
> >  > A.b_id to another valid B id and try to persist, this fails.... or
> >  > worse, it does not have any effect. Am i forced to get the B object and
> >  > perform an A.set(B) or is there any better way to do this knowing the
> >  > id? (I am trying to avoid querying B again)
> > 
> > The referenced object B is dominating the FK field b_id in A. This mean 
> > if A has no B reference OJB assume that the reference was deleted and 
> > set b_id to null. If you lookup A and B was materialized too 
> > (auto-retrieve is true in reference-descriptor in A) and then change 
> > b_id, OJB get the referenced B and override the changed b_id with the 
> > old value.
> > So you have to load the new B object and replace the referenced object in A.
> > 
> > regards,
> > Armin
> > 
> 
> Ok... I tried to do what you said (more or less) but I still have
> problems. I'm going to tell you the scenario that will help for sure. I
> get the A object, change the references (not the embedded objects but
> the Integer objects which map the FK), then I pass this object and the
> transaction to an update method. In that method using Metadata I guess
> which references this object has (*) then I read the new referenced
> objects, load them in the main object and persist... nothing happens!
> 
> The interesting point is that if i clone the main object (inside the
> update method), inspect clone's references using Metadata, load new
> referenced objects into the clone and finally I copy clone data into the
> original object: it works perfect. Now i am lost! :)
> 
> I post the code just in case.
> 
> (*) I do this because this method has to be generic in order to use it
> with many objects which are subclasses of the main class
> (BaseBusinessObject).
> 
> 
> public final void updateBOtx(BaseBusinessObject bbo,TransactionExt tx)
> throws ComputersServiceImplException,CloneNotSupportedException
>     {
> /*notice that if the lines begining with // are uncommented an the 
> lines ending in // are commented everything works, if the code is left
> just like it is now... it has no effect.*/
> 
>         Class boClass;
>         MetadataManager mm;
>         DescriptorRepository dr;
>         ClassDescriptor cld;
>         String tableName;
>         Vector references;
>         //BaseBusinessObject bboClone;
> 
>         //bboClone=bbo.cloneIt();
> 
>         try
>         {
>             logger.debug("Triggering object update");
>             if(!tx.isOpen())
>             {
>                 logger.debug("Opening transaction...");
>                 tx = (TransactionExt) odmg.newTransaction();
>                 tx.begin();
>             }
> 
>             //boClass=bboClone.getClass();
>             boClass=bbo.getClass();//
>             mm = MetadataManager.getInstance();
>             dr = mm.copyOfGlobalRepository();
>             cld = dr.getDescriptorFor(boClass);
>             //tableName = cld.getFullTableName();
> 
>             references = cld.getObjectReferenceDescriptors();
>             for (int i = 0; i < references.size(); i++)
>             {
>                 Class referencedClass;
>                 BaseBusinessObject referencedObject;
>                 String id;
>                 ObjectReferenceDescriptor reference;
> 
>                 reference = (ObjectReferenceDescriptor)
> references.get(i);
>                 referencedClass=reference.getItemClass();
>                
> //id=BeanUtils.getProperty((Object)bboClone,(String)reference.getForeignKeyFields().firstElement());
>                
> id=BeanUtils.getProperty((Object)bbo,(String)reference.getForeignKeyFields().firstElement());//
>                 logger.debug("Reference found! -
> "+(String)reference.getForeignKeyFields().firstElement()+"="+id+"
> class="+referencedClass.getName());
>                 referencedObject=getBOtx(referencedClass,id,tx);
>                
> //BeanUtils.setProperty(bboClone,reference.getAttributeName(),referencedObject);
>                
> BeanUtils.setProperty(bbo,reference.getAttributeName(),referencedObject);
>             }
>             //bbo.copy(bboClone);
> 
>             tx.lock(bbo,Transaction.WRITE);
>             
>             logger.debug("Transaction checkpoint...");            
>             tx.checkpoint();
>         }
>         catch (Exception ex)
>         {
>             tx.abort();
>             throw new ComputersServiceImplException("Exception thrown
> while updating BO in ComputerServiceImpl.updateBO()",ex.getCause());
>         }
>     }
> 
> 
> 
> 
> 

-- 
Saludos,

Martin I. Levi

Centre Tecnol�gic de Transferenci�ncia de Calor
Universitat Polit�cnica de Catalunya
www.cttc.upc.edu


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to