Return-Path: Delivered-To: apmail-incubator-open-jpa-dev-archive@locus.apache.org Received: (qmail 82811 invoked from network); 15 Nov 2006 22:53:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Nov 2006 22:53:05 -0000 Received: (qmail 60233 invoked by uid 500); 15 Nov 2006 22:53:15 -0000 Delivered-To: apmail-incubator-open-jpa-dev-archive@incubator.apache.org Received: (qmail 60205 invoked by uid 500); 15 Nov 2006 22:53:15 -0000 Mailing-List: contact open-jpa-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: open-jpa-dev@incubator.apache.org Delivered-To: mailing list open-jpa-dev@incubator.apache.org Received: (qmail 60196 invoked by uid 99); 15 Nov 2006 22:53:15 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Nov 2006 14:53:15 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [216.199.14.26] (HELO www3.mousetech.com) (216.199.14.26) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Nov 2006 14:53:01 -0800 Received: from [192.168.0.250] (mail.mousetech.com [216.199.14.19] (may be forged)) (authenticated bits=0) by www3.mousetech.com (8.13.1/8.13.1) with ESMTP id kAFMqNMw010298 for ; Wed, 15 Nov 2006 17:52:35 -0500 Message-ID: <455B9A26.8080101@mousetech.com> Date: Wed, 15 Nov 2006 17:52:22 -0500 From: Tim Holloway User-Agent: Thunderbird 1.5.0.8 (X11/20061025) MIME-Version: 1.0 To: open-jpa-dev@incubator.apache.org Subject: Documentation: re-attaching objects Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org First off: Is there an easy way to get the docs rendered in PDF format? Preferably duplex-sensitive? Speaking of which: I got burned on this a few months back trying out JDO2. It looks like the same behavior applies to JPA, and considering the time it cost me, I'd like to see something in the docs. Here goes: It's not uncommon in a webapp to detach an object from its persistence manager, then later come back and re-attach it in order to pick up details that weren't part of the original fetch set. A classic case of this is drilling down a parent-child relationship. Consider the case where a detached parent object (P) is called upon to make available a collection of unfetched child objects (C) using simple object access (e.g. "p.getC()"). To re-attach P, I invoke the EntityManager merge() method. OK, stop right there. "merge" is a doubly-unfortunate usage. First, because in this particular instance, I don't actually want any unintended changes to P to leak back to the persistent copy, since in the case in question, I'm hoping to get read-only access, and any conflicts would thus hopefully throw an exception. In fact, in many cases, even having out-of-band changes to the persistent data coming back into P might be something I'd want to know about. Fine. I want too much. So be it. I'll just have to be more careful. A more serious objection is that "merge" isn't truly a merge. The merge function does not operate in-place on the object passed to it; it creates a whole new object based on the results of the merge operation. On odd Tuesdays I can recall why that must be, but intuitively, I tend to want the original object to be re-attached, not get dealt an entirely new object. Among other things, if I'm selectively fleshing out a domain model tree, it can really shred the graph integrity if I've got oddball references to the original object in various places. Anyway, if I've grossly missed the point, please (gently) set me straight. But since I've obviously got a habit of this sort of malfeasance, I'd be very grateful if the documentation spent some extra time on the topic.