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.
-- KevinOn 12/11/07 8:25 AM, "Andrus Adamchik" <andru..bjectstyle.org> 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 > > > >
This archive was generated by hypermail 2.0.0 : Tue Dec 11 2007 - 09:00:22 EST