openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wisnes...@apache.org
Subject svn commit: r565845 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
Date Tue, 14 Aug 2007 17:38:01 GMT
Author: wisneskid
Date: Tue Aug 14 10:38:00 2007
New Revision: 565845

URL: http://svn.apache.org/viewvc?view=rev&rev=565845
Log:
Help Catalina committing OPENJPA-313.r564688.patch

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java?view=diff&rev=565845&r1=565844&r2=565845
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
Tue Aug 14 10:38:00 2007
@@ -30,6 +30,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.meta.strats.NoneClassStrategy;
@@ -189,8 +190,33 @@
             }
         }
         Object oid = ApplicationIds.fromPKValues(vals, cls);
-        if (!subs && oid instanceof OpenJPAId)
-            ((OpenJPAId) oid).setManagedInstanceType(cls.getDescribedType());
+        if (oid instanceof OpenJPAId) {
+            Class type = cls.getDescribedType();
+            if (!subs)
+                // non-polymorphic relations
+                ((OpenJPAId) oid).setManagedInstanceType(type);
+            else if (cls.getDiscriminator() != null
+                && !StringUtils.equals("none",
+                    cls.getDiscriminator().getStrategy().getAlias())) {
+                // for polymorphic relations,
+                // the type field in the oid is initially set to base type.
+                // If the discriminator value is preset in the current result,
+                // then the type field needs reset based on discriminator value.
+                // If the discriminator value is not present or invalid,
+                // ignore any exceptions being thrown.
+                // The discriminator value can potentially be null in the 
+                // database because the mapping tool does not enforce the 
+                // discriminator column 'not null'.
+                // We can not prevent other non-jpa applications from inserting
+                // a null or invalid discriminator value.
+                res.startDataRequest(cls.getDiscriminator());
+                try {
+                    type = cls.getDiscriminator().getClass(store, cls, res);
+                    ((OpenJPAId) oid).setManagedInstanceType(type);
+                } catch (Exception e) {}
+                res.endDataRequest();  
+            } 
+        }
         return oid;
     }
 



Mime
View raw message