Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 42383 invoked from network); 6 Mar 2008 02:18:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Mar 2008 02:18:20 -0000 Received: (qmail 65789 invoked by uid 500); 6 Mar 2008 02:18:16 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 65762 invoked by uid 500); 6 Mar 2008 02:18:16 -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 65753 invoked by uid 99); 6 Mar 2008 02:18:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Mar 2008 18:18:15 -0800 X-ASF-Spam-Status: No, hits=-1999.8 required=10.0 tests=ALL_TRUSTED,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Mar 2008 02:17:40 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id A7579234C089 for ; Wed, 5 Mar 2008 18:16:58 -0800 (PST) Message-ID: <2067022675.1204769818663.JavaMail.jira@brutus> Date: Wed, 5 Mar 2008 18:16:58 -0800 (PST) From: "Roger Keays (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Commented: (OPENJPA-235) SQL reordering to avoid non-nullable foreign key constraint violations MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12575537#action_12575537 ] Roger Keays commented on OPENJPA-235: ------------------------------------- As discussed on openjpa-users, the ConstraintUpdateManager breaks recursive delete operations where ON DELETE CASCADE foreign key actions are used. http://www.nabble.com/ON-DELETE-CASCADE-causes-OptimisticLockingException-td14308483.html The old OperationOrderUpdateManager doesn't have this problem. > SQL reordering to avoid non-nullable foreign key constraint violations > ---------------------------------------------------------------------- > > Key: OPENJPA-235 > URL: https://issues.apache.org/jira/browse/OPENJPA-235 > Project: OpenJPA > Issue Type: Improvement > Components: kernel > Reporter: Reece Garrett > Assignee: Patrick Linskey > Fix For: 1.1.0 > > Attachments: merge-detached.patch, merge-testcases.patch, openjpa-235-break-nullable-070716.patch, openjpa-235-break-nullable.patch, openjpa-235-test.jar, openjpa-235-test1.jar, openjpa-235-test2.zip, sqlreorder.patch, sqlReorder2.patch, sqlReorderTests.patch > > > OpenJPA does not do any SQL statement re-ordering in order to resolve foreign key constraints. Instead, objects are always inserted in the order in which the user persists the instances. When you persist in an order that would violate foreign key constraints, OpenJPA attempts to insert null and then update the foreign key value in a separate statement. If you use non-nullable constraints, though, you must persist your objects in the correct order. > This improvement re-orders SQL statements as follows: > 1. First, all insert statements execute. Inserts which have foreign keys with non-nullable constraints execute AFTER the foreign keys which they depend on have been inserted since no deferred update is possible. > 2. Next, all update statements execute. No reordering is necessary. > 3. Finally, all delete statements execute. Like inserts, deletes execute in an order which does not violate non-nullable foreign key constraints. > If a circular foreign key reference is found during the re-ordering process then re-ordering halts and the remaining unordered statements are left as is. There is nothing that can be done about the circular reference (other than fixing the schema) and the resulting SQL statements will not succeed. > The net effect is that users do not need to worry about the persistence order of their objects regardless of non-nullable foreign key constraints. The only class modified was org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager. I have included a patch which includes my modifications to OperationOrderUpdateManager and test cases. The test cases I have provided fail on the current trunk but pass with my modifications. I have also verified that I did not break anything by using maven to run all test cases with my modifications in place. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.