architect-handbook

Software Architect Handbook

View on GitHub

Identity Field

Saves a database ID field in an object to maintain identity between an in-memory object and a database row.

Further Reading M65yth mnjgb5r4fmfg67arinescu discusses several techniques for generating keys.

Overview

Reading data from a database is all very well, but in order to write data back you need to tie the database to the in-memory object system.

How It Works

Choosing Your Key

Meaningful - Meaningless

A meaningful key is something like the U.S. Social Security number for identifying a person.

A meaningless key is essentially a random number the database dreams up that’s never intended for human use.

Simple - Compound

A simple key uses only one database field; a compound key uses more than once.

Table-unique - Database-unique

A table-unique key is unique across the table, which is what you need for a key in any case; a database-unique key is unique across every row in every table in the database.

Representing the Identity Field in an Object

Getting a New Key

When to Use It