Hi, maybe someone can help me here.
I'm trying to copy a dataObject to another dataContext while keeping
it's modified state so that it will be correctly committed to the db by
the second dataContext.
Let say we have an entity with an attribute Name and a relationship
Category.
The object 1000001 exist in the db and has a Name and a Category
//Create the dataContext
DataContext dc1= DataContext.createDataContext();
DataContext dc2= DataContext.createDataContext();
//Get object from db. Modify the name.
Animal from= (Animal) DataObjectUtils.objectForPK(dc1, new
ObjectId("Animal", "animalId", 1000001));
from.setName("XXX" + new SecureRandom().nextInt());
//Get local object to dc2
//I cannot use dc2.localObject(from.getObjectId(), from);
//because the dc2 won't see the modification made in dc1.
Animal to= (Animal) dc2.localObject(from.getObjectId(), null);
dc2.getObjectStore().resolveHollow(to);
//Copy the attributes from object1 to object2
String attName;
ObjAttribute objAttribute;
ObjEntity objEntity=
from.getObjectContext().getEntityResolver().lookupObjEntity(to);
Iterator attributes = objEntity.getAttributes().iterator();
while (attributes.hasNext()) {
objAttribute = (ObjAttribute) attributes.next();
attName= objAttribute.getName();
to.writeProperty(attName, from.readPropertyDirectly(attName));
}
dc2.commitChanges();
System.out.println(from);
System.out.println(to);
Everything is committed correctly to the db but the object from has now
a Category = null
The problem is after the dc2.commitChanges() and
it comes from
org.objectstyle.cayenne.event.EventManager.DispatchThread.run() witch is
firing an event to set the relationship Category to null.
I don't know why it is doing that.
I am doing something wrong ? Is it a bug in cayenne ?
And i need context synchronization so turning it off is not an option.
I really need help on this one, can someone help me ?
Jonathan
This archive was generated by hypermail 2.0.0 : Sun Aug 27 2006 - 16:33:33 EDT