Re: Generated ID in 1.2?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue May 31 2005 - 21:04:32 EDT


Hi Joe,

I don't think I have a full understanding of your schema, so let me
clarify a few things first... First, is this a legacy schema or can you
redesign your relationships any way you want?

> Where (sessionId and locusId) are the real primary key and uniqueId is
> just used as a shortcut to another table with name/value attributes.

Whatever the logic behind it, looks like "uniqueId" behaves like a
primary key for all practical purposes. Or am I missing something?

> I do not want all three fields to be the composite PK since there
> should
> only be one (sessionId, locusId) composite key in existence.

Why not a single column - uniqueId.

> If "generated" were independent of being primary keys, then this could
> work (I think).

Aside from my suggestion above, let me point out again - "generated"
column (which might be a bad word for it .... 1.2 is still not
finalized, any ideas how to rename it?) means that the following two
conditions are true: database assigns this column a unique value on
insert AND jdbc driver knows how to return it back to the Java code.
Second part (driver support) is not there for Sybase, so this doesn't
work...

If you still think that using "uniqueId" as a single PK is not
appropriate in your case, here is another idea. Map uniqueId as a
regular object attribute, and manually run pk generator to obtain a
value for it (even though it is not a formal PK, this should work).
E.g.:

DataMap map = context.getEntityResolver().getDataMap("DataMapName");
DataNode node = context.lookupDataNode(map);
Object pk =
node.getAdapter().getPkGenerator().generatePkForDbEntity(node,
map.getDbEntity("XYZ"));
myObject.setUniqueId((Integer) pk);

This should work but I don't like this solution - it indicates that
something is wrong with schema design.

> Of course, I could just use the longer composite key as
> the reference to the attribute table but Cayenne does not really (seem
> to?) support unique composite keys (although I could test for existence
> and create if not present...)

It should... Any specific problems with it?

Andrus



This archive was generated by hypermail 2.0.0 : Tue May 31 2005 - 21:04:37 EDT