Only in case of "null" key of course, as otherwise you can determine the type of the key at generation type by looking at the ObjAttribute. Also we can handle a sub-case of the "null" key - multi-column PK. In this case the key is always ObjectId.

So we have these three cases:

1. Relationship key maps to an ObjAttribute -> we should use ObjAttribute Java type for key declaration. 2. Relationship key is null, and DbEntity has a single column PK -> we have no choice but to use java.lang.Object for key declaration. 3. Relationship key is null, and DbEntity has a multi-column PK -> we should use ObjectId for key declaration.

Andrus

On Dec 11, 2007, at 3:59 PM, Kevin Menard wrote:
Alright. Then this won't be as clean as I was hoping for. I had added a helper method to EntityUtils that would figure out the type of the map's key based on the attribute. But, if it can vary based on context, I'll just
have to have the template use Object.

--
Kevin


On 12/11/07 8:25 AM, "Andrus Adamchik" <[EMAIL PROTECTED]> wrote:


On Dec 11, 2007, at 3:05 PM, Kevin Menard (JIRA) wrote:

However, when using the default key, calling
ObjRelationship#getMapKey() returns null.  Is that expected behavior
as well?  If so, I think I'd like to see that changed.  I'm fine
with defaults not being specified in the DataMap, but the runtime
model should have all the info.

Yes this is expected behavior. What NULL means is simply that there is
no ObjAttribute for the key. Since id's in Cayenne are not class
properties by default, there's nothing to map to. Here is the logic to
extract the key in runtime:

IdMapKeyAccessor.java:

     ObjectId id = ((Persistent) object).getObjectId();

     if (id.isTemporary()) {
         return id;
     }

     Map map = id.getIdSnapshot();
     if (map.size() == 1) {
         Map.Entry pkEntry = (Map.Entry)
map.entrySet().iterator().next();
         return pkEntry.getValue();
     }

     return id;

So you see, there is a bit of fuzziness - a key can be an ObjectId for
multi-column PK and for NEW objects, or it can be a single PK value
for committed single-column PK.

Andrus

Reply via email to