I agree with this point of view to a certain extend, at least that is
how I explained it to coworkers and other interested individuals.
But there is a tiny trip hazard one should be aware of. I will five a
quick example. Consider the case you are building a system that contains
registered editors which can modify certain articles in respect of
specific permissions.
One could come to the conclusion, that the always provided and naturally
necessary email address of every editor has the inherent feature of
uniqueness and servers by this definition as a potential entity key.
Well, it does. As mentioned before it is unique and makes sense as
identity in context of the business.
And then the customer decides: use our Single Sing On, no more
registrations from the actual platform. And guess what, the SSO does not
deliver mail addresses (company security policy).
(This is a somewhat true story from my project history)
Well, if you had used this domain specific information as the key and
therefor as the reference throughout you persistence, there
(potentially) be dragons.
And for this particular reason, I always think about the probability of
breaking changes when choosing keys (or surrogate keys)
WDYT?
Cheers
Jakob
On 08/02/2014 05:46 PM, Frederik Krautwald wrote:
> An ID of an entity must come from the domain requirements, and not how the
> entity is persisted. Though I am aware that especially the Web world for
> many years has practiced creating surrogate keys for every unique thing
> they need to store; from a database point of view, this is bad practice,
> and primary keys should be identified by the data stored. That is, we look
> for candidate keys, which could be a single field or a combination of
> fields that make the entity unique. If, and only if, none such can be
> identified, we could create a surrogate key which uniquely identifies the
> entity. However, as already mentioned, I know the common practice is to
> just create surrogate keys, such as incrementing integers, for everything.
> The problem with this is that a number, such as 42, doesn’t provide any
> value to the business. Think about, I have To-do entity no. 42 here. Well,
> yes, then what? What does that number tell you? Well, if you *know* about