Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 27436 invoked from network); 24 Mar 2008 15:14:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Mar 2008 15:14:28 -0000 Received: (qmail 29368 invoked by uid 500); 24 Mar 2008 15:14:26 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 29218 invoked by uid 500); 24 Mar 2008 15:14:26 -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 29208 invoked by uid 99); 24 Mar 2008 15:14:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Mar 2008 08:14:26 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of michael.d.dick@gmail.com designates 209.85.162.181 as permitted sender) Received: from [209.85.162.181] (HELO el-out-1112.google.com) (209.85.162.181) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Mar 2008 15:13:47 +0000 Received: by el-out-1112.google.com with SMTP id y26so1203484ele.4 for ; Mon, 24 Mar 2008 08:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=hktaT9QkPHWxtBlhF8RxBEhrFOts8hIX5NRQPJCf38I=; b=FFeY1N6J2wdDYb8wA26dL2saNM5zlQ3uFWFblNWlYGq8xq7XLt/PEubi17b/UTuHKVtRbi2fPasG/YV9pigYbzZ6kz8qFFyw8Uz0H9+4U4LDL2fEWtF0JQrfumU/bDSbzotR4u4tOsfPRZhnClA51+k85IUzjEyykuuUqLzsiUg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=EpOhwI+sB1FF0NOTiS3XVWatenlgtxRRIcb3Vhi4PzbWmWQPxA+p38WQ8/PTBuwFm0w2yO8B1/kO03LneD/FsLWypDGFBQkz9+DbXZnyDs39iztwLQvJXz/grE0TWzwzQDEaGyQPxa7GbVUr6JLhN9njbEuMphylYf1t2VJsCoQ= Received: by 10.114.56.1 with SMTP id e1mr11887736waa.52.1206371603046; Mon, 24 Mar 2008 08:13:23 -0700 (PDT) Received: by 10.114.195.16 with HTTP; Mon, 24 Mar 2008 08:13:22 -0700 (PDT) Message-ID: <72c1350f0803240813m28bbbc7at3b189a055d8f4aea@mail.gmail.com> Date: Mon, 24 Mar 2008 10:13:23 -0500 From: "Michael Dick" To: users@openjpa.apache.org, bardolf@seznam.cz Subject: Re: JPA update entities every (even empty) commit In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_10095_29266135.1206371603034" References: <72c1350f0803221018u27daf7eeh41b1076b23ff5460@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_10095_29266135.1206371603034 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Bardolf, I don't think there's a way to do a partial commit without detaching the entities you don't want to update. The OpenJPAEntityManager interface provides some utility methods which detach all entities in a collection, which might make detaching a set of entities easier though. Regarding the UPDATE and DELETE issue you're seeing, which version of OpenJPA are you using? I ran a quick test with v 1.0.1 and I'm not seeing that behavior. -Mike On Sun, Mar 23, 2008 at 12:09 AM, bardolf wrote: > Hi Michael, > thank you for your response, it makes sense for me. My misunderstanding > came from wrong understanding of persist method. I wrongly assumed, that > the persist method provides functionality to store selected managed > objects. > > I see now, that all managed objects are updated in DB during commit. Is > there any possibility to choose just objects I want to update (except > detaching object I don't want to update)? > > When I call remove on a managed (and changed) object, why does UPDATE > get called before DELETE? > > > Thanks Bardolf > > Michael Dick wrote: > > Hi Bardolf, > > > > In the example above you're using an application managed EntityManager. > > Application managed EMs are considered extended persistence contexts by > > default (ie the lifecycle of the persistence context can cross > > transactions). > > > > In this environment when you call EntityManager.find() a managed entity > will > > be returned. Since the entity is managed any changes you make to it will > be > > committed when you commit the transaction. > > > > If you don't want the entity to be managed you can call > EntityManager.clear() > > which detaches all entities or you can call > > OpenJPAEntityManager.detach(myEntity) > > to detach a single instance. The code might look something like this : > > > > EntityManager em = > > javax.persistence.Persistence > > .createEntityManagerFactory("JavaApplication3PU").createEntityManager(); > > Address ad = em.find(Address.class,1); > > ad.setMyProperty(xxx); > > > > em.clear(); // detach all managed entities > > > > // Detach a single entity > > // OpenJPAPersistence.cast(em).detach(ad); > > > > em.getTransaction().begin(); > > > > // if you decide you want the changes to be made after all uncomment > this > > line > > // ad = em.merge(ad); > > > > em.getTransaction().commit(); > > > > I'm writing this from memory so this might not quite match up. > > > > Hope this helps, > > -Mike > > > > On Fri, Mar 21, 2008 at 8:36 PM, bardolf wrote: > > > >> Hi all, > >> I have following question. Why JPA call updates on all changed entities > >> during commit even though persist wasn't called. > >> > >> [snip] > >> EntityManager em = > >> javax.persistence.Persistence.createEntityManagerFactory > >> ("JavaApplication3PU").createEntityManager(); > >> Address ad = em.find(Address.class,1); > >> ad.setMyProperty(xxx); > >> em.getTransaction().begin(); > >> em.getTransaction().commit(); > >> [/snip] > >> > >> And even though I didn't call persist, changes are updated in database. > >> WHY??? > >> > >> Thanks B. > >> > >> > > > > ------=_Part_10095_29266135.1206371603034--