cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1446648 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
Date Fri, 15 Feb 2013 15:55:35 GMT
Author: aadamchik
Date: Fri Feb 15 15:55:35 2013
New Revision: 1446648

URL: http://svn.apache.org/r1446648
Log:
CAY-1794 Duplicate attributes in discriminator columns of PersistentDescriptor

(cherry picked from commit 0014b8c15ddf7a71ae5b8bdb3e82909191c49c8b)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?rev=1446648&r1=1446647&r2=1446648&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
Fri Feb 15 15:55:35 2013
@@ -18,8 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.reflect;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.dba.TypesMapping;
@@ -265,7 +265,10 @@ public abstract class PersistentDescript
 
         if (qualifier != null) {
 
-            final Set<ObjAttribute> attributes = new HashSet<ObjAttribute>();
+            // using map instead of a Set to collect attributes, as
+            // ObjEntity.getAttribute may return a decorator for attribute on
+            // each call, resulting in dupes
+            final Map<String, ObjAttribute> attributes = new HashMap<String, ObjAttribute>();
             final DbEntity dbEntity = descriptor.getEntity().getDbEntity();
 
             qualifier.traverse(new TraversalHelper() {
@@ -300,19 +303,18 @@ public abstract class PersistentDescript
                                         .getJavaBySqlType(attribute.getType()));
                             }
 
-                            attributes.add(objectAttribute);
+                            attributes.put(objectAttribute.getName(), objectAttribute);
                         }
                     }
                     else if (node.getType() == Expression.OBJ_PATH) {
                         String path = node.getOperand(0).toString();
-                        attributes.add((ObjAttribute) descriptor
-                                .getEntity()
-                                .getAttribute(path));
+                        ObjAttribute attribute = (ObjAttribute) descriptor.getEntity().getAttribute(path);
+                        attributes.put(path, attribute);
                     }
                 }
             });
 
-            descriptor.setDiscriminatorColumns(attributes);
+            descriptor.setDiscriminatorColumns(attributes.values());
             descriptor.setEntityQualifier(qualifier);
         }
     }



Mime
View raw message