Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 74149 invoked from network); 4 Feb 2008 23:14:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Feb 2008 23:14:50 -0000 Received: (qmail 76461 invoked by uid 500); 4 Feb 2008 23:14:42 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 76425 invoked by uid 500); 4 Feb 2008 23:14:42 -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 76416 invoked by uid 99); 4 Feb 2008 23:14:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Feb 2008 15:14:42 -0800 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 plinskey@gmail.com designates 209.85.162.176 as permitted sender) Received: from [209.85.162.176] (HELO el-out-1112.google.com) (209.85.162.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Feb 2008 23:14:27 +0000 Received: by el-out-1112.google.com with SMTP id s27so692044ele.13 for ; Mon, 04 Feb 2008 15:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=uOP6ggkQUSs7clYOsbMv4QrQhBt2+oOK/y8TreJsIv8=; b=Ion/asF4zFHGfGmWhNu1EacY3p2OOGWvHGzey/0I9EMGJFCg71Vk05fAZ5F0Qj/zaDeCBYSoWpiuXNNoEW5N3weGRVrChGAMzKUGdY6p5iAztRa0HL98FC5xf/FLnIoDSnfye8+YIG4U9v9U8JOhvVTRfalD5It9qDMQUMI3Qts= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=SmaIaLZDC0yPzDWtBXkwRv9sSAW/OrgoZaDMKrHtfHhz9yIU7/2kd77udDdjqovpargiQAWfGImtZZuDsIJMVjWmclHkZlOhzQbnP5SojSWuIqQVcoR4ZHsCEa9RA837SJeBW8HciHQBR0cau3Z2G2DfytZNlSEGegBDEZmhqRk= Received: by 10.151.11.17 with SMTP id o17mr3203930ybi.51.1202166858774; Mon, 04 Feb 2008 15:14:18 -0800 (PST) Received: by 10.150.158.20 with HTTP; Mon, 4 Feb 2008 15:14:18 -0800 (PST) Message-ID: <7262f25e0802041514p7b289a6dg256db200f9032f2a@mail.gmail.com> Date: Mon, 4 Feb 2008 15:14:18 -0800 From: "Patrick Linskey" To: dev@openjpa.apache.org Subject: Re: optimistic locking bug? In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <75A0D7B9-86EA-44B9-AB9C-1491102D219D@joost.com> <7262f25e0802041143y2540fd4dpffdbb55cb41f99a9@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org > So, as a "best practice" for dealing with joined inheritance, have no > cacading deletes for FKs in the db schema? Does your metadata (annotations and XML) identify that you've got a cascading constraint on that table? I would expect that if such metadata exists, or if you tell OpenJPA to ask the DB for such metadata (and it reports it properly), then your current code would be fine. -Patrick On Feb 4, 2008 2:31 PM, Geir Magnusson Jr. wrote: > That was my conclusion too, but I thought that when I was looking at > the SQL logging, that wasn't the case. > > So, as a "best practice" for dealing with joined inheritance, have no > cacading deletes for FKs in the db schema? > > geir > > > > On Feb 4, 2008, at 2:43 PM, Patrick Linskey wrote: > > > It sounds like OpenJPA is issuing delete statements for both tables, > > but the cascade constraint from the first delete is causing the second > > row to be deleted before the second delete statement is evaluated. So, > > when the dependent row to be deleted is not found, OpenJPA assumes > > that this is because a different transaction deleted the record. > > > > -Patrick > > > > On Feb 3, 2008 3:02 PM, Geir Magnusson Jr. wrote: > >> Single threaded code, 1 tx, my machine, no else one around... > >> > >> Code : > >> > >> > >> /* > >> * first _delete_ the ones we have > >> */ > >> for (ShowInsertionPoint ip : list) { > >> OMUtil.getEntityManager().remove(ip); > >> } > >> > >> OMUtil.getEntityManager().flush(); > >> > >> > >> Exception in thread "main" >> error> org.apache.openjpa.persistence.OptimisticLockException: > >> Optimistic locking errors were detected when flushing to the data > >> store. The following objects may have been concurrently modified in > >> another transaction: [com.joost.model.ShowInsertionPoint-4590, > >> com.joost.model.ShowInsertionPoint-4593] > >> > >> at > >> org > >> .apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java: > >> 2104) > >> at > >> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1954) > >> at > >> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852) > >> at > >> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1623) > >> at > >> org > >> .apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java: > >> 973) > >> at > >> org > >> .apache > >> .openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java: > >> 488) > >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > >> at > >> sun > >> .reflect > >> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: > >> 39) > >> at > >> sun > >> .reflect > >> .DelegatingMethodAccessorImpl > >> .invoke(DelegatingMethodAccessorImpl.java: > >> 25) > >> at java.lang.reflect.Method.invoke(Method.java:585) > >> at org.springframework.orm.jpa.SharedEntityManagerCreator > >> $ > >> SharedEntityManagerInvocationHandler > >> .invoke(SharedEntityManagerCreator.java:180) > >> at $Proxy8.flush(Unknown Source) > >> at > >> com > >> .joost > >> .md > >> .tools > >> .importexport > >> .fields > >> .show > >> .ShowInsertionPointsField > >> .internalModify(ShowInsertionPointsField.java: > >> 209) > >> > >> Note, that I'm not explicitly using optimistic locking. > >> > >> A ShowInsertionPoint is a sub of InsertionPoint, using joined > >> inheritance. > >> > >> The tables : > >> > >> CREATE TABLE InsertionPoint ( > >> id int(11) unsigned NOT NULL auto_increment, > >> itemType varchar(64) collate ascii_bin NOT NULL COMMENT 'The name > >> of the table that defines any subclass information.', > >> insertionTime int(8) unsigned NOT NULL COMMENT 'in milliseconds', > >> sourceCode int(4) unsigned NOT NULL default '1', > >> quality float unsigned default NULL COMMENT 'Percentage (from 0.0 > >> to 100.0) giving a (human) estimate of how well this insertion point > >> is placed wrt the content.', > >> PRIMARY KEY (id), > >> KEY InsertionPoint_sourceCodeIndex (sourceCode), > >> CONSTRAINT InsertionPoint_sourceCodeFK FOREIGN KEY (sourceCode) > >> REFERENCES InsertionPointSourceCode (`code`) > >> ) ENGINE=InnoDB AUTO_INCREMENT=35960 DEFAULT CHARSET=ascii > >> COLLATE=ascii_bin; > >> > >> > >> CREATE TABLE ShowInsertionPoint ( > >> id int(11) unsigned NOT NULL, > >> showId int(11) unsigned NOT NULL, > >> PRIMARY KEY (id), > >> KEY ShowInsertionPoint_showIdIndex (showId), > >> CONSTRAINT ShowInsertionPoint_idFK FOREIGN KEY (id) REFERENCES > >> InsertionPoint (id) ON DELETE CASCADE ON UPDATE CASCADE, > >> CONSTRAINT ShowInsertionPoint_showIdFK FOREIGN KEY (showId) > >> REFERENCES VideoShow (id) ON DELETE CASCADE ON UPDATE CASCADE > >> ) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin; > >> > >> The whole problem went away when I removed the constraint : > >> > >> CONSTRAINT ShowInsertionPoint_idFK FOREIGN KEY (id) REFERENCES > >> InsertionPoint (id) ON DELETE CASCADE ON UPDATE CASCADE, > >> > >> from ShowInsertionPoint. > >> > >> Am I doing something wrong? Or is there a bug in OpenJPA? > >> > >> tia > >> > >> geir > >> > >> > >> > > > > > > > > -- > > Patrick Linskey > > 202 669 5907 > > -- Patrick Linskey 202 669 5907