O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Do not use database-generated IDs

Most modern database servers, such as MS SQL Server or Oracle, offer the possibility to use database-generated IDs for Primary Keys. In SQL Server, we can auto generate IDs by defining the column to be an identity column. In Oracle, we would use sequences to generate new IDs.

When using NHibernate or any other ORM framework, you will want to avoid this feature of the database as it has many drawbacks.

One of the criteria for a good Primary Key is that it is assigned by an NHibernate Persistent Object ID (POID) generator. Automatic assignment lets NHibernate manage the assignment of Primary Keys. NHibernate has the "smarts" baked right in to create those IDs for us and put them back into our object.

Whenever a record ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required