Return-Path: Delivered-To: apmail-incubator-cayenne-user-archive@locus.apache.org Received: (qmail 61785 invoked from network); 27 Aug 2006 22:26:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Aug 2006 22:26:50 -0000 Received: (qmail 6171 invoked by uid 500); 27 Aug 2006 22:26:49 -0000 Delivered-To: apmail-incubator-cayenne-user-archive@incubator.apache.org Received: (qmail 6152 invoked by uid 500); 27 Aug 2006 22:26:49 -0000 Mailing-List: contact cayenne-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-user@incubator.apache.org Delivered-To: mailing list cayenne-user@incubator.apache.org Received: (qmail 6143 invoked by uid 99); 27 Aug 2006 22:26:49 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2006 15:26:49 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: 218.214.79.9 is neither permitted nor denied by domain of marcin@ish.com.au) Received: from [218.214.79.9] (HELO fish.ish.com.au) (218.214.79.9) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2006 15:26:47 -0700 Received: from [10.194.9.2] (helo=[10.194.9.2]) by fish.ish.com.au with esmtp (Exim 4.43) id 1GHTEZ-0003E1-IO for cayenne-user@incubator.apache.org; Mon, 28 Aug 2006 08:36:07 +1000 Mime-Version: 1.0 (Apple Message framework v752.2) In-Reply-To: <44F20182.2030806@rcda.ca> References: <44F20182.2030806@rcda.ca> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <78B591AA-8116-482C-9BA0-009FE03AADBC@ish.com.au> Content-Transfer-Encoding: quoted-printable From: Marcin Skladaniec Subject: Re: DataContext synchronization bug ? Date: Mon, 28 Aug 2006 08:26:19 +1000 To: cayenne-user@incubator.apache.org X-Mailer: Apple Mail (2.752.2) X-Spam-Score: -1.4 (-) X-Spam-Report: -1.4 ALL_TRUSTED Passed through trusted hosts only via SMTP X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hello Jonathan Please take a closer look on the localObject() method. Straight from javadocs : "Returns an object local to this DataContext and matching the =20 ObjectId. If prototype is not null, local object is refreshed with =20 the prototype values. In case you pass a non-null second parameter, you are responsible for =20= setting correct persistence state of the returned local object, as =20 generally there is no way for Cayenne to determine the resulting =20 local object state." If you have still problems please mention what version of cayenne are =20= you using. Marcin --------------------------> ish http://www.ish.com.au Level 1, 30 Wilson Street Newtown 2042 Australia phone +61 2 9550 5001 fax +61 2 9550 4001 On 28/08/2006, at 6:33 AM, Jonathan B=E9lisle wrote: > 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 =20 > db by the second dataContext. > > Let say we have an entity with an attribute Name and a relationship =20= > Category. > The object 1000001 exist in the db and has a Name and a Category > > //Create the dataContext > DataContext dc1=3D DataContext.createDataContext(); > DataContext dc2=3D DataContext.createDataContext(); > > //Get object from db. Modify the name. > Animal from=3D (Animal) DataObjectUtils.objectForPK(dc1, new ObjectId=20= > ("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=3D (Animal) dc2.localObject(from.getObjectId(), null); > dc2.getObjectStore().resolveHollow(to); > > //Copy the attributes from object1 to object2 String attName; > ObjAttribute objAttribute; > ObjEntity objEntity=3D from.getObjectContext().getEntityResolver=20 > ().lookupObjEntity(to); > Iterator attributes =3D objEntity.getAttributes().iterator(); > while (attributes.hasNext()) { > objAttribute =3D (ObjAttribute) attributes.next(); > attName=3D 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 =20= > now a Category =3D null > > The problem is after the dc2.commitChanges() and > it comes from =20 > org.objectstyle.cayenne.event.EventManager.DispatchThread.run() =20 > 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