I'm working with SQL Server, and most of tables have identity columns of type int. And now, I just came across a book, that tells it's not a good idea to use this mechanism. What are the cons/pros of using identity columns when using NHibernate as ORM?
I'm not an NHibernate expert, but as far as I understand it, using identity columns breaks the UnitOfWork and causes additional round-trips to the database.
Fabio Maulo (then project lead of NHibernate, I'm not sure if he still is today) has a blog post where he explains this in detail:
Identity: The never ending story
Here is another (longer) blog post with example code:
NH2.1.0: generators behavior explained
However, note that both blog posts are about three years old and talk about NH 2.1.0, and the current version as of today is NH 3.3. But I assume that the problem as described by Fabio still exists today.
It makes no difference if they are an identitity column or not. The role of an ORM is to map the data entities to the database not to dictate the database structure/design. I have used an implementation with identity columns and it works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With