openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r892430 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
Date Sat, 19 Dec 2009 04:50:29 GMT
Author: faywang
Date: Sat Dec 19 04:50:24 2009
New Revision: 892430

URL: http://svn.apache.org/viewvc?rev=892430&view=rev
Log:
OPENJPA-1438: fix wherePrimaryKey for entity using derived identity

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java?rev=892430&r1=892429&r2=892430&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowImpl.java Sat
Dec 19 04:50:24 2009
@@ -183,7 +183,8 @@
         while (mapping.getTable() != getTable())
             mapping = mapping.getPCSuperclassMapping();
         Column[] cols = mapping.getPrimaryKeyColumns();
-        flushJoinValues(sm, cols, cols, io, set);
+        Object oid = mapping.useIdClassFromParent() ? sm.getObjectId() : null;
+        flushJoinValues(sm, oid, cols, cols, io, set);
     }
 
     public void setForeignKey(ForeignKey fk, OpenJPAStateManager sm)
@@ -219,7 +220,7 @@
     private void flushForeignKey(ForeignKey fk, ColumnIO io,
         OpenJPAStateManager sm, boolean set)
         throws SQLException {
-        flushJoinValues(sm, fk.getPrimaryKeyColumns(), fk.getColumns(),
+        flushJoinValues(sm, null, fk.getPrimaryKeyColumns(), fk.getColumns(),
             io, set);
         if (sm != null) {
             Column[] cols = fk.getConstantColumns();
@@ -250,7 +251,7 @@
      * @param set whether this should be flushed as an update or
      * as a where condition
      */
-    private void flushJoinValues(OpenJPAStateManager to, Column[] toCols,
+    private void flushJoinValues(OpenJPAStateManager to, Object oid, Column[] toCols,
         Column[] fromCols, ColumnIO io, boolean set)
         throws SQLException {
         if (to == null) {
@@ -278,8 +279,13 @@
             }
 
             join = toMapping.assertJoinable(toCols[i]);
-            val = join.getJoinValue(to, toCols[i], (JDBCStore) to.
-                getContext().getStoreManager().getInnermostDelegate());
+            if (oid != null)
+                val = join.getJoinValue(oid, toCols[i], (JDBCStore) to.
+                    getContext().getStoreManager().getInnermostDelegate());
+            else
+                val = join.getJoinValue(to, toCols[i], (JDBCStore) to.
+                    getContext().getStoreManager().getInnermostDelegate());
+                
             if (set && val == null) {
                 if (canSet(io, i, true))
                     setNull(fromCols[i]);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java?rev=892430&r1=892429&r2=892430&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMappedById.java
Sat Dec 19 04:50:24 2009
@@ -610,6 +610,10 @@
         MedicalHistory3 m = em.find(MedicalHistory3.class, new PersonId3("f_1", "l_1"));
         MedicalHistory3 m0 = medicals3.get("f_1");
         assertEquals(m, m0);
+        
+        em.getTransaction().begin();
+        em.remove(m);
+        em.getTransaction().commit();
     }
 
     public void queryObj6() { 



Mime
View raw message