Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 56916 invoked from network); 17 Sep 2009 13:40:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Sep 2009 13:40:57 -0000 Received: (qmail 25533 invoked by uid 500); 17 Sep 2009 13:40:56 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 25480 invoked by uid 500); 17 Sep 2009 13:40:56 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 25469 invoked by uid 99); 17 Sep 2009 13:40:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Sep 2009 13:40:55 +0000 X-ASF-Spam-Status: No, hits=-0.6 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [64.18.2.24] (HELO exprod7og123.obsmtp.com) (64.18.2.24) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 17 Sep 2009 13:40:45 +0000 Received: from source ([209.85.210.182]) by exprod7ob123.postini.com ([64.18.6.12]) with SMTP ID DSNKSrI8R6pBpxy96VcnSRjK9d4EjI3HmMfI@postini.com; Thu, 17 Sep 2009 06:40:25 PDT Received: by yxe12 with SMTP id 12so59546yxe.1 for ; Thu, 17 Sep 2009 06:40:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.114.3 with SMTP id m3mr1181846ybc.56.1253194822639; Thu, 17 Sep 2009 06:40:22 -0700 (PDT) In-Reply-To: <004a01ca3748$d02159a0$70640ce0$@com> References: <001e01ca36fe$431fc8b0$c95f5a10$@com> <002201ca3704$577235e0$0656a1a0$@com> <002801ca370c$d53fbda0$7fbf38e0$@com> <002d01ca371f$49e6d960$ddb48c20$@com> <004a01ca3748$d02159a0$70640ce0$@com> Date: Thu, 17 Sep 2009 09:40:22 -0400 Message-ID: Subject: Re: SingleFieldManager crash From: Daryl Stultz To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=00151748e8c03ce02c0473c628e9 X-Virus-Checked: Checked by ClamAV on apache.org --00151748e8c03ce02c0473c628e9 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Sep 16, 2009 at 11:41 PM, C N Davies wrote: > I've put a try catch around my code that is triggering the issue, I've written the following code to assist my debugging: private void collectJpaDebug(String name, Object object, StringBuffer sb, EntityManager em) { sb.append(name + ": " + object); try { if (object != null) { sb.append("-"); OpenJPAEntityManager emo = (OpenJPAEntityManager) em; sb.append("EM:"); sb.append(emo.isDetached(object) ? "D" : "d"); sb.append(emo.isDirty(object) ? "X" : "x"); sb.append(emo.isNewlyPersistent(object) ? "N" : "n"); sb.append(emo.isPersistent(object) ? "P" : "p"); sb.append(emo.isRemoved(object) ? "R" : "r"); sb.append(emo.isTransactional(object) ? "T" : "t"); EntityManagerImpl emi = (EntityManagerImpl) em; final Broker broker = emi.getBroker(); sb.append(" BK:"); sb.append(broker.isDetachedNew() ? "C" : "c"); sb.append(broker.isDirty(object) ? "X" : "x"); sb.append(broker.isNew(object) ? "N" : "n"); sb.append(broker.isPersistent(object) ? "P" : "p"); sb.append(broker.isDeleted(object) ? "R" : "r"); sb.append(broker.isTransactional(object) ? "T" : "t"); OpenJPAStateManager sm = broker.getStateManager(object); sb.append(" SM:"); if (sm != null) { sb.append(sm.isDetached() ? "D" : "d"); sb.append(sm.isDirty() ? "X" : "x"); sb.append(sm.isNew() ? "N" : "n"); sb.append(sm.isPersistent() ? "P" : "p"); sb.append(sm.isProvisional() ? "V" : "v"); sb.append(sm.isDeleted() ? "R" : "r"); sb.append(sm.isTransactional() ? "T" : "t"); } else { sb.append("null"); } } } catch (Throwable exc) { sb.append(exc); } sb.append("\n"); } This generates a number of "flags" for the various properties. So for this case: EntityManager em = getEm(); A a = em.find(A.class, 1); // EM:dxnPrt BK:cxnPrt SM:dxnPvrt em.close(); em = getEm(); // a different em // EM:Dxnprt BK:cxnprt SM:null a = new A(); // EM:dxnprt BK:cxnprt SM:null a.setId(1); // EM:dxnprt BK:cxnprt SM:null I've added the resulting "flags" after the operations. It seems the only time an object has a state manager is when it is currently managed. Detached objects have no sm. I guess I had the "feeling" the state manager was part of the enhanced object, but it looks like it's in the em. So going back to the code of SingleFieldManager: *private* *void* preFlushPC(ValueMetaData vmd, Object obj, *boolean* logical, OpCallbacks call) { *if* (obj == *null*) *return*; OpenJPAStateManager sm; *if* (vmd.getCascadePersist() == ValueMetaData.*CASCADE_NONE*) { *if* (!_broker.isDetachedNew() && _broker.isDetached(obj)) *return*; // allow but ignore sm = _broker.getStateManager(obj); *if* (sm == *null* || !sm.isPersistent()) *throw* *new* InvalidStateException( *_loc*.get("cant-cascade-persist", vmd)) .setFailedObject(obj); } *else* { I think it's fair to say that it's failing on sm == null rather than !sm.isPersistent() since the FailedObject is at least detached and possibly "unmanaged" altogether (whatever that means). Since my debugging always returns on the blue line, the question is now why, once in a great while, does it now think that the object is not detached (read: not formerly managed by a different em). There's also the possiblility that _broker.isDetachedNew() is wrong - I don't know what that means yet. -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com mailto:daryl@6degrees.com --00151748e8c03ce02c0473c628e9--