Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 97742 invoked from network); 4 Nov 2007 12:07:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Nov 2007 12:07:22 -0000 Received: (qmail 92643 invoked by uid 500); 4 Nov 2007 12:07:10 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 92630 invoked by uid 500); 4 Nov 2007 12:07:09 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 92621 invoked by uid 99); 4 Nov 2007 12:07:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Nov 2007 04:07:09 -0800 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mad7@runbox.com designates 193.71.199.94 as permitted sender) Received: from [193.71.199.94] (HELO aibo.runbox.com) (193.71.199.94) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Nov 2007 12:07:10 +0000 Received: from [10.9.9.161] (helo=patch.runbox.com) by greyhound.runbox.com with esmtp (Exim 4.50) id 1IoeFR-0008Su-ND for user@cayenne.apache.org; Sun, 04 Nov 2007 13:06:37 +0100 Received: from [83.222.49.143] (helo=Slick) by patch.runbox.com with esmtpa (uid:69848 ) (Exim 4.50) id 1IoeFR-0004Se-7Y for user@cayenne.apache.org; Sun, 04 Nov 2007 13:06:37 +0100 Message-ID: <87BB2889DAA044B3AAC7AF1487E62F83@Slick> Reply-To: "Marc A. Donis" From: "Marc A. Donis" To: References: <43209ABAA0DC4CDEB5EBF36C4AF9A642@schwartz> <13561667.post@talk.nabble.com> In-Reply-To: Subject: Re: 2.0.4: child DataContext & localObject Date: Sun, 4 Nov 2007 13:02:01 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6000.16480 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16545 X-Virus-Checked: Checked by ClamAV on apache.org Thanks, Andrus. Should I submit a bug report? If so, can you tell me where I can do so? Honestly, I'm a bit surprised that I seem to be the first person ever to want to do such a thing. Having a shared DataContext for reference data seems like fairly standard practice. Accessing that shared DataContext from another DataContext which happens to be a nested context, seems like something every app would need to do at some point... Regards, Marc ----- Original Message ----- From: "Andrus Adamchik" To: Sent: Sunday, November 04, 2007 11:39 Subject: Re: 2.0.4: child DataContext & localObject > Could be a bug then. Yes, 'localObject' should do the right thing for > committed objects. > > Andrus > > > On Nov 4, 2007, at 12:23 PM, Marc A. Donis wrote: > >> Hi, thanks for the reply. >> >> The ref object is committed. In fact, it is read-only. >> >> btw, I found a solution, which I do not like much: >> >> @Override >> public void setToOneTarget(String relationshipName, DataObject value, >> boolean setReverse) { >> if (value != null && value.getDataContext() != this.getDataContext()) >> { >> DataContext dc = getDataContext(); >> value = dc.refetchObject(value.getObjectId()); >> } >> super.setToOneTarget(relationshipName, value, setReverse); >> } >> >> Clearly, this results in an unnecessary fetch to bring the reference >> object into the master object's DataContext. I'd still very much like >> to understand why simply doing "value = (DataObject) >> dc.localObject(value.getObjectId(), null);" causes the relationship to >> be reset to null by DataContext.onContextFlush(). Is this a bug? >> >> Regards, >> Marc >> >> ----- Original Message ----- From: "Andrus Adamchik" >> >> To: >> Sent: Sunday, November 04, 2007 09:43 >> Subject: Re: 2.0.4: child DataContext & localObject >> >> >>> Hi Marc, >>> >>> is the target object ('ref') committed, or is it in some other state >>> (new, modified, etc.)? >>> >>> Andrus >>> >>> On Nov 3, 2007, at 12:36 PM, mad7777 wrote: >>>> Just to follow up... I've tried doing: >>>> >>>> @Override >>>> public void setToOneTarget(String relationshipName, DataObject value, >>>> boolean setReverse) { >>>> if (value != null && value.getDataContext() != this.getDataContext () >>>> && >>>> value.getDataContext() != this.getDataContext()) { >>>> DataContext dc = getDataContext(); >>>> value = (DataObject) dc.localObject(value.getObjectId(), value); >>>> value.setPersistenceState(PersistenceState.COMMITTED); >>>> } >>>> super.setToOneTarget(relationshipName, value, setReverse); >>>> } >>>> >>>> ... but alas, the result is the same as below. >>>> >>>> I admit I don't understand what is going on here. It seems that I >>>> can't use >>>> a shared DataContext in conjunction with a nested (i.e. child) >>>> DataContext? >>>> Is this a bug, or am I just going about this all wrong?? >>>> >>>> Marc >>>> >>>> >>>> >>>> mad7777 wrote: >>>>> >>>>> Hi, >>>>> >>>>> I am seeing a strange interaction between child DataContexts and >>>>> localObject. If I set a to-one relationship from an object residing >>>>> in a >>>>> child context to another object which lives in that context's >>>>> parent, I >>>>> see: >>>>> >>>>> org.apache.cayenne.CayenneRuntimeException: [v.2.0.4 October 12 2007] >>>>> Cannot >>>>> set object as destination of relationship abuseStatus because it is >>>>> in a >>>>> different DataContext >>>>> >>>>> So I do: >>>>> >>>>> @Override >>>>> public void setToOneTarget(String relationshipName, DataObject >>>>> value, >>>>> boolean setReverse) { >>>>> if (value != null && value.getDataContext() != >>>>> this.getDataContext() && >>>>> value.getDataContext() != this.getDataContext()) { >>>>> DataContext dc = getDataContext(); >>>>> value = (DataObject) dc.localObject(value.getObjectId(), null); >>>>> } >>>>> super.setToOneTarget(relationshipName, value, setReverse); >>>>> } >>>>> >>>>> in the child context object's class, which works fine (but seems >>>>> like it >>>>> should not be necessary?). >>>>> >>>>> But what I really want is: >>>>> >>>>> DataContext refDataContext = DataContext.createDataContext(); >>>>> CayenneDataObject ref = ...// get reference from refDataContext >>>>> DataContext userDataContext = >>>>> DataContext.createDataContext().createChildDataContext(); >>>>> CayenneDataObject obj = >>>>> userDataContext.createAndRegisterNewObject(MasterObject.class); >>>>> obj.setRef(ref); >>>>> >>>>> In other words, the obj's context (the child context) is not a child >>>>> of >>>>> the >>>>> referenced object's context. >>>>> In combination with the first bit of code, I now get: >>>>> >>>>> org.apache.cayenne.validation.ValidationException: [v.2.0.4 October >>>>> 12 >>>>> 2007] Validation has failed. >>>>> Validation failure for MasterObject.ref: "ref" is required. >>>>> >>>>> because all the to-one relationship values set in this way are reset >>>>> to >>>>> null >>>>> during userDataContext.commitChanges()! >>>>> >>>>> The stack looks like this: >>>>> >>>>> MasterObject.setToOneTarget(UnAmourDataObject.java:11) *** value >>>>> == null in this call >>>>> org.apache.cayenne.access.ChildDiffLoader.arcCreated >>>>> (ChildDiffLoader.java:120) >>>>> org.apache.cayenne.access.ObjectDiff$ArcOperation.apply >>>>> (ObjectDiff.java:428) >>>>> org.apache.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:97) >>>>> org.apache.cayenne.access.ObjectStoreGraphDiff.apply >>>>> (ObjectStoreGraphDiff.java:136) >>>>> org.apache.cayenne.access.DataContext.onContextFlush >>>>> (DataContext.java:1188) >>>>> org.apache.cayenne.access.DataContext.onSync(DataContext.java:1167) >>>>> org.apache.cayenne.access.DataContext.flushToParent >>>>> (DataContext.java:1234) >>>>> org.apache.cayenne.access.DataContext.commitChanges >>>>> (DataContext.java:1138) >>>>> >>>>> Thoughts? Comments? Suggestions? >>>>> >>>>> Thanks, >>>>> Marc >>>>> >>>>> >>>>> >>>> >>>> -- >>>> View this message in context: http://www.nabble.com/2.0.4%3A- child- >>>> DataContext---localObject-tf4734281.html#a13561667 >>>> Sent from the Cayenne - User mailing list archive at Nabble.com. >>>> >>>> >>> >> >> > >