Question: Entities and Primary Keys and "Primary Keys"

"Ashley Aitken" <[email protected]>
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
Howdy All,

I read somewhere that is it wise, for example with category codes, to
have the primary key (a database construct) plus a unique code for each
category as a part of the object model (I will call that the entity
primary key).  

This enables objects that refer to the category to use the unique
category code (entity primary key) as opposed to the database primary
key and thus to survive restoration of the category code table (ie where
the primary keys may change but the category codes will stay the same)
from backup etc.

I have two questions:

1.  This would seem to apply to all entities and thus we should not use
the database primary key as the primary way of distinguishing entities
in relationships etc.  Hence we should have the database primary key and
a separate entity primary key (which will become part of the object
model but should be set uniquely once and not changed) for each entity. 
We should use the entity primary key for foreign keys and relationship
joins etc.

2.  If this is the case, I guess we have to set up an index for this
entity primary key manually (as I don't believe EOModeller will do it).

Of course, this question would not arise if we use the entity "primary
key" as the database primary key (if you know what I mean) but we are
generally advised not to do this (because having the real primary key as
a part of the object model leaves it open to erroneous changes etc).  

I hope that is all understandable.

Any comments or suggestions?

Cheers,
Ashley Aitken.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.