From dev-return-17335-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Sun Sep 12 12:41:17 2010 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 85719 invoked from network); 12 Sep 2010 12:41:17 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Sep 2010 12:41:17 -0000 Received: (qmail 11381 invoked by uid 500); 12 Sep 2010 12:41:17 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 11003 invoked by uid 500); 12 Sep 2010 12:41:13 -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 10986 invoked by uid 99); 12 Sep 2010 12:41:12 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Sep 2010 12:41:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Sep 2010 12:40:54 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o8CCeW5H014074 for ; Sun, 12 Sep 2010 12:40:33 GMT Message-ID: <29858458.139891284295232699.JavaMail.jira@thor> Date: Sun, 12 Sep 2010 08:40:32 -0400 (EDT) From: "agurkas (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Commented: (OPENJPA-1651) Unique colums automatically defined as non-nullable (part 2) In-Reply-To: <29415949.23141273074423462.JavaMail.jira@thor> 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-1651?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12908454#action_12908454 ] agurkas commented on OPENJPA-1651: ---------------------------------- Dear openjpa developers. This is a serious and long standing bug which is still not fixed in openjpa 2.0.1. The problem is some people using openjpa might not realize that openjpa is setting unique fields to not null without any warning and the consequences can be horrible. In some particular scenarious one might not find records in the database even if those do exist (imagine this happening in production database for more excitement) Let me show one simple example. @Entity @Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "a", "b" }) }) public class TestEntity { @ManyToOne @JoinColumn(nullable = true, name = "a") private EntityA a; //optional @ManyToOne @JoinColumn(nullable = false, name = "b") private EntityB b; //required //getters setters ommited for readability } @Test public void test() { EntityB b = getEntityBService().find(1); TestEntity entity = new TestEntity(); entity.setB(b); getTestEntityService().save(entity); //so record is saved in database with a = 0 not a = NULL value as expected and b = 1 //now try to find this TestEntity by unique constraints meaning by EntityA == null and EntityB with id = 1 EntityA a = null; EntityB b = getEntityBService().find(1); TestEntity entity = getTestEntityService().findByAB(a, b); Assert.assertNotNull(entity); //result is FAILURE entity not found this is underlying openjpa generated sql that shows why it fails SELECT (... ommited...) FROM TestEntity t0 LEFT OUTER JOIN EntityA t1 ON t0.a = t1.id LEFT OUTER JOIN EntityB t2 ON t0.b = t2.id WHERE (t0.a IS NULL AND t0.b = 1) it cannot be found in the TestEntity table as we have 0 not a NULL value for optional entity a to avoid this we do run our tool to fix database structure to avoid this and possibly other scenarios but a openjpa fix would be nice to have. regards > Unique colums automatically defined as non-nullable (part 2) > ------------------------------------------------------------ > > Key: OPENJPA-1651 > URL: https://issues.apache.org/jira/browse/OPENJPA-1651 > Project: OpenJPA > Issue Type: Bug > Reporter: Mark Struberg > Assignee: Pinaki Poddar > Attachments: openjpa-test.zip > > > Continuing the discussion from OPENJPA-1387. The original issue was closed and marked as shipped in OpenJPA 2.0.0 (one of the betas) - it should not appear in 2.0.1 as well - thus the need for a new issue. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.