openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r475321 - /incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Date Wed, 15 Nov 2006 17:43:03 GMT
Author: awhite
Date: Wed Nov 15 09:43:02 2006
New Revision: 475321

URL: http://svn.apache.org/viewvc?view=rev&rev=475321
Log:
Fix bug in which abstract JPA entities were being mapped to tables when the
declared inheritance strategy for the hierarchy was TABLE_PER_CLASS (which 
actually means table-per-concrete-class).


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

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?view=diff&rev=475321&r1=475320&r2=475321
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Wed Nov 15 09:43:02 2006
@@ -413,8 +413,6 @@
      */
     protected ClassStrategy namedStrategy(ClassMapping cls) {
         String name = cls.getMappingInfo().getStrategy();
-        if (name == null)
-            return null;
         return instantiateClassStrategy(name, cls);
     }
 
@@ -423,6 +421,8 @@
      */
     protected ClassStrategy instantiateClassStrategy(String name,
         ClassMapping cls) {
+        if (name == null)
+            return null;
         if (NoneClassStrategy.ALIAS.equals(name))
             return NoneClassStrategy.getInstance();
 
@@ -650,17 +650,27 @@
             return instantiateClassStrategy((String) strat, cls);
         if (strat != null)
             return (ClassStrategy) strat;
+        
+        // see if there is a declared hierarchy strategy
+        ClassStrategy hstrat = null;
+        for (ClassMapping base = cls; base != null && hstrat == null;) {
+            hstrat = instantiateClassStrategy(base.getMappingInfo().
+                getHierarchyStrategy(), cls);
+            base = base.getMappedPCSuperclassMapping();
+        }
 
+        // the full strategy as applied to a hierarchy is a
+        // table-per-concrete-class strategy, so don't map abstract types
+        if (hstrat instanceof FullClassStrategy
+            && !cls.isManagedInterface()
+            && Modifier.isAbstract(cls.getDescribedType().getModifiers()))
+            return NoneClassStrategy.getInstance();
+        
         ClassMapping sup = cls.getMappedPCSuperclassMapping();
         if (sup == null)
             return new FullClassStrategy();
-
-        while (sup.getMappedPCSuperclassMapping() != null)
-            sup = sup.getMappedPCSuperclassMapping();
-        String subStrat = sup.getMappingInfo().getHierarchyStrategy();
-        if (subStrat != null)
-            return instantiateClassStrategy(subStrat, cls);
-
+        if (hstrat != null)
+            return hstrat;
         return new FlatClassStrategy();
     }
 



Mime
View raw message