Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 25750 invoked from network); 28 Aug 2009 19:38:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Aug 2009 19:38:18 -0000 Received: (qmail 44838 invoked by uid 500); 28 Aug 2009 19:38:18 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 44761 invoked by uid 500); 28 Aug 2009 19:38:17 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 44751 invoked by uid 99); 28 Aug 2009 19:38:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2009 19:38:17 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists+1214986235816-210739@n2.nabble.com designates 216.139.236.80 as permitted sender) Received: from [216.139.236.80] (HELO jim.nabble.com) (216.139.236.80) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2009 19:38:07 +0000 Received: from jim ([127.0.0.1]) by jim.nabble.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 28 Aug 2009 14:37:45 -0500 Date: Fri, 28 Aug 2009 14:37:45 -0500 (CDT) From: Michael Dick To: dev@openjpa.apache.org Message-ID: <1251488265723-3536988.post@n2.nabble.com> In-Reply-To: References: <89c0c52c0908280925h4c72a4b4oa74f6dad95cb9a1d@mail.gmail.com> <72c1350f0908281035j6946b65eh6472ec4e63b06589@mail.gmail.com> <1251481607429-3536258.post@n2.nabble.com> Subject: Re: SingleFieldManager.preFlushPC MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: michael.d.dick@gmail.com X-OriginalArrivalTime: 28 Aug 2009 19:37:45.0738 (UTC) FILETIME=[047166A0:01CA2817] X-Virus-Checked: Checked by ClamAV on apache.org Daryl Stultz wrote: > > On Fri, Aug 28, 2009 at 1:46 PM, Michael Dick > wrote: > >> >> The scenario you've described doesn't sound right (maybe I need a >> refresher). The new ShippingInstructions object should be unmanaged >> unless >> you've managed to inject a StateManager into it (which would be a good >> trick). >> > > No, I've never injected anything in my life. I'm working in Tomcat. I'm > still confused, if an object has a state manager it's managed? Doesn't a > detached object have a state manager? Here's my unit test (as clean as > possible): > My fault, I shouldn't have mentioned injecting a StateManager - there's almost no way you could have done that. Detachted Entities do have a StateManager some of the time. You can configure the detached SM to be transient in which case it'll be lost at serialization time (you can also remove the detached SM entirely though). Obligatory link to http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_graph docs Lets just look at your example for now though and I'll try not to muddy the waters any more. Daryl Stultz wrote: > > User editingUser = em.find(User.class, userOneId); > ScheduledAssignment saOne = setup.insertScheduledAssignment(...); > saOne is persisted and committed in a separate transaction? Daryl Stultz wrote: > > TimeTrackingEntry entry = new TimeTrackingEntry(); > entry.setScheduledAssignment(saOne); > entry.setStartTime(startTime); > entry.setStartTime(endTime); > em = setup.getEntityManager(); // different em than above, simulating > different thread/web transaction > User editingUserClone = new User(); > editingUserClone.setId(editingUser.getId()); > editingUserClone.setArchived(editingUser.isArchived()); > ... more property copying > entry.setAddedBy(editingUserClone); > entry.setAddedOn(Calendar.getInstance().getTime()); > em.getTransaction().begin(); > em.merge(entry); > em.getTransaction().commit(); // expected this to fail, but it works > Aha, you're calling em.merge which is slightly different than em.persist. Merge handles detached, or unmanaged entities differently. If a row in the database matches the entity you're merging we'll issue an update (there's some version checking here to help prevent the app from shooting itself in the foot too). The error message we gave you is a bit misleading in this case. We should be using Cascade.MERGE instead of Cascade.PERSIST. This may be a case where we find the row in the database and issue an update, if the row isn't found we go back and do a 'normal' persist - resulting in the error message you see. >From what you've said the row always exists in the database though - so maybe this isn't a perfect match.. -mike Daryl Stultz wrote: > >> >> Out of idle curiosity do you have any properties set in persistence.xml? >> Or >> should I be able to reproduce this with OpenJPA's default configuration? >> > > > /> > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:daryl@6degrees.com > > -- View this message in context: http://n2.nabble.com/SingleFieldManager-preFlushPC-tp3534271p3536988.html Sent from the OpenJPA Developers mailing list archive at Nabble.com.