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

Using database-generated IDs

Using database-generated IDs for our entities at first glance seems very appealing and straightforward. However, a closer look at the problem at hand reveals that using database-generated IDs is effectively an anti-pattern and should be strictly avoided.

Database-generated IDs only make sense in scenarios where our application is sharing the database with other applications that can also update the data therein. In this case, we might want to rely on the database to generate the necessary primary keys and guarantee their uniqueness. However, I have already discussed in earlier chapters of this book why we should prevent this scenario from happening and insist that our application owns its own database.

NHibernate provides ...

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