Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1DA0F721E for ; Thu, 29 Dec 2011 12:45:50 +0000 (UTC) Received: (qmail 38386 invoked by uid 500); 29 Dec 2011 12:45:49 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 38364 invoked by uid 500); 29 Dec 2011 12:45:49 -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 38356 invoked by uid 99); 29 Dec 2011 12:45:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Dec 2011 12:45:49 +0000 X-ASF-Spam-Status: No, hits=1.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of curtisr7@gmail.com designates 74.125.83.46 as permitted sender) Received: from [74.125.83.46] (HELO mail-ee0-f46.google.com) (74.125.83.46) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Dec 2011 12:45:41 +0000 Received: by eekc4 with SMTP id c4so13829423eek.33 for ; Thu, 29 Dec 2011 04:45:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=iPk/ownn0b3+vhCuZt5uqmIfeIGui8/90aoO9J03FJo=; b=Aa3l49aHU6ljgTRmPAT7zXy/Hj8Go99b9Vrbz1xJJK/H+s48aKeJrgtiB056hZ1UN3 JOPEXNxMXTyNCp4daWmmC8KSP/rFbNEKOqOEEq4m0V8LtqqRlRf2UoZ0+qhfE/IBvviZ B5EPFz1XyAXWCkyqnb2kfRssrcJIU+1UaNQx8= MIME-Version: 1.0 Received: by 10.14.99.197 with SMTP id x45mr14370434eef.114.1325162721393; Thu, 29 Dec 2011 04:45:21 -0800 (PST) Received: by 10.213.7.140 with HTTP; Thu, 29 Dec 2011 04:45:21 -0800 (PST) Received: by 10.213.7.140 with HTTP; Thu, 29 Dec 2011 04:45:21 -0800 (PST) In-Reply-To: References: Date: Thu, 29 Dec 2011 06:45:21 -0600 Message-ID: Subject: Re: temporary entity left in the database after being deleted. From: Rick Curtis To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=bcaec52c6a5f473b3404b53a7d23 X-Virus-Checked: Checked by ClamAV on apache.org --bcaec52c6a5f473b3404b53a7d23 Content-Type: text/plain; charset=ISO-8859-1 Try something like this: E_App temp = new E_App(); temp.setPrimaryKey(temporaryPK); temp = em.merge(temp); Thanks, Rick On Dec 29, 2011 5:47 AM, "Pawel Veselov" wrote: > Hi. > > I'm not sure what I'm doing wrong here. I'm creating a temporary entity, > within transaction, deleting the entity before committing. I need that > temporary entity in the database during the transaction though... My code > is roughly doing this: > > EntityManager em; // have it > E_App temp = new E_App(); > temp.setPrimaryKey(temporaryPK); > em.merge(temp); > em.flush(); > // the temporary entity is in the database, as I wanted (verified) > // do other crazy stuff now, not touching temp instance in any way > // (except from side direct DB queries that don't modify any managed > columns) > em.remove(temp); > em.flush(); // I added that line in hope it might make a difference, but it > doesn't > // some other stuff, also changes persistence context > em.getTransaction().commit(); > > The problem is that temp shows up in the database after commit. > > There is a statement in the spec that says that if you call remove() on a > new entity, it's a no-op. I agree it should be, but I don't think new and > merged entity qualifies for being "new". I tried to trace this down, and > from what I can see, BrokerImpl.delete(Object,OpCallbacks) gets from > getStateManagerImpl() for that object, passing it as a second arg into > delete(Object, StateManagerImpl, OpCallbacks), which effectively makes it a > no-op. > > Thank you, > Pawel. > --bcaec52c6a5f473b3404b53a7d23--