Back on this old chestnut again…
- Always use a synthetic primary key.
- Never use a primary key with business meaning (in case my last point wasn’t clear).
- Call your primary key something that can’t be mistaken for something with business meaning. ID is usually good. PK works too.
- Don’t include the table name in any of your column names. They already know which table they belong to.
- Use Longs as primary keys, and generate them from a sequence.
- Use unique and ‘NOT NULL’ constraints to identify secondary keys (the ones that DO have business meaning).
- Use hibernate.
O/R mapping is a compromise. Bending both your DB and your object layer slightly to acknowledge this fact is far better than bending one of them over backwards to avoid changing the other. Using synthetic primary keys is almost always a good move anyway, and helps object persistence a lot. Having a consistent primary key name and datatype makes automated persistence much easier (ie. code-generation).