Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 87189 invoked from network); 22 Feb 2011 02:41:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Feb 2011 02:41:04 -0000 Received: (qmail 29675 invoked by uid 500); 22 Feb 2011 02:41:04 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 29182 invoked by uid 500); 22 Feb 2011 02:41:02 -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 29158 invoked by uid 99); 22 Feb 2011 02:41:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Feb 2011 02:41:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Feb 2011 02:40:59 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 6AA431B1116 for ; Tue, 22 Feb 2011 02:40:38 +0000 (UTC) Date: Tue, 22 Feb 2011 02:40:38 +0000 (UTC) From: "Michael Dick (JIRA)" To: dev@openjpa.apache.org Message-ID: <306831509.7241.1298342438418.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] Resolved: (OPENJPA-635) child record foreign key column set to null on deletion of parent record even foreign key delete action is set to "restrict" MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-635?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Michael Dick resolved OPENJPA-635. ---------------------------------- Resolution: Cannot Reproduce The latest versions of OpenJPA handle this case before the SQL goes to the database. You'll see something like this instead : org.apache.openjpa.persistence.InvalidStateException: The field "parent" of instance "org.apache.openjpa.persistence.relations.CascadingOneManyChild@6c89db9a" contained a null value; the metadata for this field specifies that nulls are illegal. at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:558) at org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:496) at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2971) at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40) I'm resolving the issue as cannot reproduce - since the original problem only occurred with Kodo. If there's another use case for the patch, please reopen. > child record foreign key column set to null on deletion of parent record even foreign key delete action is set to "restrict" > ---------------------------------------------------------------------------------------------------------------------------- > > Key: OPENJPA-635 > URL: https://issues.apache.org/jira/browse/OPENJPA-635 > Project: OpenJPA > Issue Type: Bug > Components: jdbc > Affects Versions: 1.1.0 > Environment: Windows > Reporter: Xiaoqin Feng > Assignee: Michael Dick > Priority: Trivial > Attachments: openjpa-635.patch > > > When using an inverse key collection mapping, if you delete the parent > object, the FK column of the corresponding child record(s) are set to null. > If there is a null constraint on the column (as is normally the case in a FK > column), this will result in a null constraint error. But we expect to get FK constraint error. > For example, > @ManyToOne(optional=false) > @JoinColumn(name="PARENT_ID", nullable=false) > @ForeignKey > private OneManyParent parent; > If we set "nullable=false" in JoinColumn, then it throws FK constraint exception as expected. > But since the default deleteAction value for "ForeignKey" annotation is "restrict", even "nullable=false" is not set, it should behave as "restrict". > Note: for "Column" and "JoinColumn", the default value is "nullable=true". > I checked RelationToManyInverseKeyFieldStrategy.delete(), ForeignKey deleteAction is not evaluated at all. It only check if Column is nullable. > I will try to attach test case soon. -- This message is automatically generated by JIRA. - For more information on JIRA, see: http://www.atlassian.com/software/jira