For those people that use NHibernate and similar stuff, why do you use it? To me, it seems easier to write the SQL manually.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Productivity and cross-database portability are two reasons. Hibernate/NHibernate or other ORMs allow one to easily serialize objects to/from the database without having to hand-code (and maintain) lots of SQL statements to do exactly that. I don’t know about you, but writing and keeping tons of CRUD queries up-to-date for the hundreds of objects in our system is not my idea of fun, nor a good use of a developer’s time! I’m not sure if NHibernate has a similar mechanism, but the Hibernate Synchronizer plugin for Eclipse is truly fantastic: take a mapping file and make objects and DAOs automagically. Good stuff!
Performance (in the L1 and L2 caches) is another reason — though of course you can certainly write boneheaded findAll() type code which makes this moot, but overall they’ve put a LOT of time and effort into this, so it’s more code you don’t have to reinvent yourself.
Now sure, there’s a nontrivial learning curve for N/Hibernate but like most things once you get it you’ll wonder how you lived without it.
That said, ORMs aren’t a silver bullet (though they are very good, generally) and they’re not appropriate for all circumstances. We still write SQL for complicated or highly optimized queries. That said, the developers on my team swear by Hibernate and would probably revolt if we went back to writing straight SQL everywhere.