You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/12/19 16:15:39 UTC

svn commit: r605573 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java

Author: aadamchik
Date: Wed Dec 19 07:15:38 2007
New Revision: 605573

URL: http://svn.apache.org/viewvc?rev=605573&view=rev
Log:
fixing incorrect logic in getMapKeyType - must use target entity for attribute lookup

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

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java?rev=605573&r1=605572&r2=605573&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java Wed Dec 19 07:15:38 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.gen;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
@@ -275,22 +276,32 @@
      */
     public String getMapKeyType(final ObjRelationship relationship) {
 
+        ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
+
         // If the map key is null, then we're doing look-ups by actual object key.
         if (relationship.getMapKey() == null) {
 
             // If it's a multi-column key, then the return type is always ObjectId.
-            DbEntity dbEntity = objEntity.getDbEntity();
+            DbEntity dbEntity = targetEntity.getDbEntity();
             if ((dbEntity != null) && (dbEntity.getPrimaryKeys().size() > 1)) {
                 return ObjectId.class.getName();
             }
 
-            // If it's a single column key or no key exists at all, then we really don't know what the key type is,
+            // If it's a single column key or no key exists at all, then we really don't
+            // know what the key type is,
             // so default to Object.
             return Object.class.getName();
         }
 
-        // If the map key is a non-default attribute, then fetch the attributue and return its type.
-        final ObjAttribute attribute = (ObjAttribute) objEntity.getAttribute(relationship.getMapKey());
+        // If the map key is a non-default attribute, then fetch the attribute and return
+        // its type.
+        ObjAttribute attribute = (ObjAttribute) targetEntity.getAttribute(relationship
+                .getMapKey());
+        if (attribute == null) {
+            throw new CayenneRuntimeException("Invalid map key '"
+                    + relationship.getMapKey()
+                    + "', no matching attribute found");
+        }
 
         return attribute.getType();
     }



Re: svn commit: r605573 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/ apache/cayenne/gen/EntityUtils.java

Posted by Kevin Menard <km...@servprise.com>.
My bad.  My simple test case worked out the other way and I don't map to Map
types at all.  I'll try to be more cautious in the future.

-- 
Kevin


On 12/19/07 10:15 AM, "aadamchik@apache.org" <aa...@apache.org> wrote:

> Author: aadamchik
> Date: Wed Dec 19 07:15:38 2007
> New Revision: 605573
> 
> URL: http://svn.apache.org/viewvc?rev=605573&view=rev
> Log:
> fixing incorrect logic in getMapKeyType - must use target entity for attribute
> lookup