You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by fa...@apache.org on 2010/10/27 22:55:01 UTC

svn commit: r1028095 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/

Author: faywang
Date: Wed Oct 27 20:55:00 2010
New Revision: 1028095

URL: http://svn.apache.org/viewvc?rev=1028095&view=rev
Log:
OPENJPA-1857: fix the exception to be thrown by OpenJPA when wrong JoinColumn annotation is specified.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5a.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestDerivedIdentity.java   (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java?rev=1028095&r1=1028094&r2=1028095&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java Wed Oct 27 20:55:00 2010
@@ -1528,7 +1528,7 @@ public abstract class MappingInfo
         Column tmplate = new Column();
         tmplate.setIdentifier(name);
         if (!constant) {
-            Column tcol = foreign.getColumn(targetName);
+            Column tcol = foreign.getColumn(targetName, false); 
             if (tcol == null)
                 throw new MetaDataException(_loc.get(prefix + "-bad-fktarget",
                     new Object[]{ context, targetName, name, foreign }));

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java?rev=1028095&r1=1028094&r2=1028095&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DynamicSchemaFactory.java Wed Oct 27 20:55:00 2010
@@ -158,6 +158,10 @@ public class DynamicSchemaFactory
             return getColumn(name, null);
         }
 
+        public Column getColumn(DBIdentifier name, boolean create) {
+            return getColumn(name, null, create);
+        }
+
         public Column getColumn(DBIdentifier name) {
             return getColumn(name, null);
         }
@@ -172,11 +176,15 @@ public class DynamicSchemaFactory
         }
 
         public Column getColumn(DBIdentifier name, DBDictionary dict) {
+            return getColumn(name, dict, true);
+        }
+        
+        public Column getColumn(DBIdentifier name, DBDictionary dict, boolean create) {
             if (DBIdentifier.isNull(name))
                 return null;
 
             Column col = super.getColumn(name);
-            if (col != null)
+            if (col != null || !create)
                 return col;
 
             // Ensure only valid column name(s) are added to the table

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java?rev=1028095&r1=1028094&r2=1028095&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java Wed Oct 27 20:55:00 2010
@@ -322,6 +322,9 @@ public class Table
         return _colMap.get(DBIdentifier.toUpper(name));
     }
 
+    public Column getColumn(DBIdentifier name, boolean create) {
+        return getColumn(name);
+    }
     
     /**
      * Affirms if this table contains the column of the given name without any 

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5a.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5a.java?rev=1028095&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5a.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5a.java Wed Oct 27 20:55:00 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.enhance.identity;
+import java.io.Serializable;
+
+import javax.persistence.*;
+
+@Entity
+@IdClass(DependentId5.class)
+public class Dependent5a implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    @Id
+    String name;
+    
+    @Id
+    @JoinColumns({
+       @JoinColumn(name="FIRSTNAME", referencedColumnName="xFIRSTNAME"),
+       @JoinColumn(name="LASTNAME", referencedColumnName="yLASTNAME")
+    })
+    @ManyToOne
+    Employee5 emp;
+
+    public Dependent5a(String name, Employee5 emp) {
+        this.name = name;
+        this.emp = emp;
+    }
+
+    public Dependent5a(DependentId5 dId, Employee5 emp){
+        this.name = dId.getName();
+        this.emp = emp;
+    } 
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Dependent5a.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestDerivedIdentity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestDerivedIdentity.java?rev=1028095&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestDerivedIdentity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestDerivedIdentity.java Wed Oct 27 20:55:00 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.enhance.identity;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.ArgumentException;
+import org.apache.openjpa.persistence.PersistenceException;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestDerivedIdentity extends SingleEMFTestCase {
+    public void setUp() throws Exception {
+        super.setUp(DROP_TABLES, Dependent5a.class, Employee5.class, EmployeeId5.class);
+    }
+
+    public void testIncorrectJoinColumnAnnotation() {
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.getTransaction().commit();
+        } catch (PersistenceException e) {
+            fail("Wrong exception");
+        } catch (ArgumentException e) {
+            //Correct exception is thrown:
+            //"org.apache.openjpa.persistence.enhance.identity.Dependent5a.emp" defines a target of "xFIRSTNAME" 
+            //for column "FIRSTNAME", but that target does not exist in table "Employee5".
+        }
+        
+        
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestDerivedIdentity.java
------------------------------------------------------------------------------
    svn:eol-style = native