NHibernate 3.0 Cookbook
RickJWagner writes "Are you a .Net developer? Do you have to persist your application objects to a database? If so, I know of a book you might be interested in, Packt Publishing's NHibernate 3.0 Cookbook. NHibernate is a port of the popular Hibernate object-relational mapper (ORM, for those who like TLAs.) An object-relational mapper is a framework that lets the developer get and retrieve application state from a database, and it does so in an efficient, non-intrusive, and flexible manner. Hibernate is the top of the line ORM implementation, yet it's easy enough to learn that even a newbie will find it easy to get started." Read on for the rest of Rick's review.
NHibernate 3.0 Cookbook
author
Dentler Jason
pages
328
publisher
Packt Publishing
rating
7/10
reviewer
RickJWagner
ISBN
184951304X
summary
The ultimate "how-to" reference for NHibernate 3.0
This book is written in Packt's 'Cookbook' style, which means it's really a series of how-to templates that guide the reader through some goal-centric activity. A 'recipe' is a formula for accomplishing something, like setting up a session for a web application, or using a profiler with NHibernate, or creating a validator class. You may not know what some of these things do-- but you will when you read the recipe! Each recipe follows a repeated pattern, with sub-sections "Getting Ready", "How to do it", "How it works", "There's More". At first glance, this can be a little deceptive for readers of technical books-- there's really no lengthy text sections that explain the basics of the tool in the early chapters of the book. You might be lulled into thinking this means there's no explanation for how things work, but that would be wrong! The truth is, there is plenty of good NHibernate theory and explanation, it's just that it's contained within the "How it Works" and "There's More" section of each instructional section, not in a chapter devoted to overview just by itself. For this reason, I'd urge bookshelf browsers to be sure to read one topic through front-to-back thoroughly, to get a feel for how the book presents theory as well as practical hands-on-the-keyboard instruction.
As far as content goes, there is a lot of useful content in this book. The author presents 70 different recipes for activites that range from the basic (i.e. your first class-to-database mappings) to the unusual (i.e. using NHibernate Spatial for solving distance-related problems.) The author offers plenty of good text in most of these, but again-- don't be upset by the placement of the high-level material. It's all there, it's just placed a little differently than what you'd find in most technical books.
The book is easy to read. The text is plain and straight to the point, and the author's writing style is quite readable. The code examples are likewise clean and well-formatted. (By the way, I'd urge you to go to Packt's site to get the source bundle if you buy the book. There's a lot of code referenced, you certainly wouldn't want to type it all by hand if you can get it handed to you.) The book runs a little over 300 pages, and most of the type is generously spaced. This is not a strong theoretical reference, but it is more than adequate as a primer for the vast majority of the tasks you'd want to accomplish with NHibernate.
So who is this book good for? I'd give it high marks for .Net developers who want to use NHibernate, regardless of experience level with the tool. I say that because there are enough use cases presented that there is almost certainly a subset of new material for almost anyone. How about Java Hibernate users? I think it's a decent book for them-- NHibernate is a very close port of the base product, so a Java user can get something out of this book, too. (For that crowd, this would obviously not be a good primary choice, but is worthwhile reading if you already have a Java go-to reference for Hibernate.) For anyone else wanting a good high-level overview of ORM use-- I'd say this book is only of marginal value. This is because the bulk of the explanatory material is presented in the context of 'how to' accomplish some particular task and isn't easily accessible without skipping from recipe to recipe.
By the way, lest you think NHibernate is only for .Net devs, I mostly ran the code samples under MonoDevelop on Ubuntu. This was my first adventure with MonoDevelop (the open source IDE for Mono, which itself is an open source, multi-platform port of .Net.) I was pleasantly surprised by the level of polish in the development environment, it really is a nice environment. Again, if you're a Java developer, I'd consider this book a decent learning supplement but would not recommend it as a primary for Hibernate proper.
You can purchase NHibernate 3.0 Cookbook from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
As far as content goes, there is a lot of useful content in this book. The author presents 70 different recipes for activites that range from the basic (i.e. your first class-to-database mappings) to the unusual (i.e. using NHibernate Spatial for solving distance-related problems.) The author offers plenty of good text in most of these, but again-- don't be upset by the placement of the high-level material. It's all there, it's just placed a little differently than what you'd find in most technical books.
The book is easy to read. The text is plain and straight to the point, and the author's writing style is quite readable. The code examples are likewise clean and well-formatted. (By the way, I'd urge you to go to Packt's site to get the source bundle if you buy the book. There's a lot of code referenced, you certainly wouldn't want to type it all by hand if you can get it handed to you.) The book runs a little over 300 pages, and most of the type is generously spaced. This is not a strong theoretical reference, but it is more than adequate as a primer for the vast majority of the tasks you'd want to accomplish with NHibernate.
So who is this book good for? I'd give it high marks for .Net developers who want to use NHibernate, regardless of experience level with the tool. I say that because there are enough use cases presented that there is almost certainly a subset of new material for almost anyone. How about Java Hibernate users? I think it's a decent book for them-- NHibernate is a very close port of the base product, so a Java user can get something out of this book, too. (For that crowd, this would obviously not be a good primary choice, but is worthwhile reading if you already have a Java go-to reference for Hibernate.) For anyone else wanting a good high-level overview of ORM use-- I'd say this book is only of marginal value. This is because the bulk of the explanatory material is presented in the context of 'how to' accomplish some particular task and isn't easily accessible without skipping from recipe to recipe.
By the way, lest you think NHibernate is only for .Net devs, I mostly ran the code samples under MonoDevelop on Ubuntu. This was my first adventure with MonoDevelop (the open source IDE for Mono, which itself is an open source, multi-platform port of .Net.) I was pleasantly surprised by the level of polish in the development environment, it really is a nice environment. Again, if you're a Java developer, I'd consider this book a decent learning supplement but would not recommend it as a primary for Hibernate proper.
You can purchase NHibernate 3.0 Cookbook from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Packt Publishing == $hill review == Slashvertisement.
Shit like this is why I have no compunctions about fully blocking all banner ads on Slashdot at all times, since long before they had that "disable advertising" checkbox.
P.S. does Slashdot ever have a book review where the reviewer really does not like the book and straight-up recommends that we should not buy it? You'd expect to see those on occasion in a non-advertising non-product-placement honest unbiased list of reviews. Strangely enough they're unheard-of on Slashdot. Why, it's almost as though they're really just ads.
Fuck astroturfing, fuck shills, and fuck deceptive advertising. And especially fuck those great enablers, the useful idiot assholes who defend it and pretend like it's legitimate.
Take a look at the Castle Project, which implements Active Record on top of nHibernate.
It's very nicely done.
Why are you letting these clowns ruin our country?
In Soviet Russia, we had gross government propaganda. Now, in Free Capitalist America, we have access to much better, and more refined marketing techniques. And it's all you can eat!
Build your own energy sources from scratch. http://otherpower.com/
I had the misfortune of developing with NHibernate. The root of the problem was that the engineers who started the project didn't know anything about database programming and just used NHibernate as a magic persistance layer. (These guys would write foreach loops that would suck most of the database into RAM.) Ultimately, as I learned the tool, I found that it just makes data access more complicated then it needs to be. In order to use it right, you have to know the underlying database programming concepts, which are simpler and easier to learn then the NHibernate library.
To make matters worse, when I used NHibernate, there was a bug in runtime code generation, which was very hard to track down and impossible to fix.
My opinion: Stick with a simple ADO -> Object mapper and write queries as-needed. If you use NHibernate, stick with the basic CRUD features. Don't rely on a more complicated library to handle things like transactions, lazy-loading, and relationship mapping. Be very careful introducing relationships into the business objects, especially automatically-populated ones. And, whatever you do, if you end up working in a project where the senior engineers and/or people who started the project treat NHibernate as a "magic persistance layer," RUN!!!
Oh, and if you work on a project that wants a "magic persistance layer," because the engineers don't get databases, investigate document databases like MongoDB, Couch, ect. The document model maps a lot better to the object-oriented way of doing things, thus it's a lot harder for programmers who don't get databases to screw them up.
No, I will not work for your startup
You see how he defined his acronyms, and what NHibernate was for? Thats how you do a good summary. You only hear people bitching when the summary is bad. Good summaries never get praise around here.
This thing is completely irrelevant to my interests, but thank you very much Rick for your summary. It probably saved a lot of people time.
and it does so in an efficient, non-intrusive, and flexible manner
Bwahahahaha!!!
"Persist" is not a transitive verb.
Member the guy who reviewed anything and everything and always got trounced by the readers here? To where did he slither off? Sledge? Or Sludge?
LINQ to SQL is much better than nHibernate.
If any one of the "Free" (as in Java) Software evangelists tries to convince you that their tools on par with .NET, just show them LINQ to SQL and watch their arrogance turn in to amazement.
Yeah, having to ask that question is pretty hilarious. You can be pretty certain that any relevant developer today knows C#.
I use Nhibernate daily at work and the time it saves for projects is significant. SQL Select statements are easy to write yes, but for projects with CRUD statements for 50 tables with up to 80 columns in each I will take as much help as I can get.
Yeah, all programs for the CLR are written in C#, all programs for Windows are written in managed code, all the world (including the iPhone) runs Windows or has a working CLR implementation ...
Whereas outside of your windows-application world you got there, hardly anyone knows C#. ... Mostly because 90% of what it was good for is going web-services. Bye~
They do. I've been struggling with commercial and free ones since C++ was the hottest environment around and they all basically do the same thing: spit out useless code that is impossible to optimise on a large database. You can't tune it reliably, you end up with indexes out the kazoo all over your database trying to catch all the special cases that the damn OR mapper makes up and they all have truly, ugly, broken interfaces to anything a normal database programmer uses like stored procedures.
I wrote one myself for the last project I worked on and, yep, it sucked just as hard as the commercial offerings for all the same reason.
They are, however, infinitely superior to object databases which truly are the spawn of the devil.
NHibernate's implementation might be fine for Java but sucks for Desktop applications. Instead of paying the cost of parsing the object mapping files once (when the web server is started) you pay for it every time you start your application. It also guarantees that your efficiency is awful because of the way it's designed. Do yourself a favor and use something else.
-- Programming with boost is like building a house with lego. It's a cool but I wouldn't want to live in it
I have this book, it is trash. It sort of assumes that you are already very familiar with NHibernate, and some of the 'recipes' are just plain wrong / poorly explained. For example, they never mention that to use FluentNHibernate for configuration in Nhibernate 3.0, you have to go find and build the source yourself. Not a big deal, but should certainly be part of the 'recipe'. This is just the first oversight of many that come to mind.
Also, what's the ratio of non-packt publishing to packt publishing books? This publisher seems to have come out of nowhere, push out a ton of second-rate crap, then try and stealth market via this sort of thing. I haven't really found anything buy them that's even been worth pirating, honestly.
ORM is anything but efficient.
Also, my experience of ORM so far it is for Newbs who cannot comprehend the data structures by themselves, making it doubly inefficient.
Well, maybe one day i'll see a good example where it actually is efficient and powerfull :)
Pulsed Media Seedboxes
Folks do know that Microsoft started including Entity Framework in .Net, and that there are connectors that support it for MySql, MsSql, and PostGre right? Why would you add another dependency to a project when the .Net runtime already provides this?
If you are a .NET developer and want to use an ORM, use ADO.NET's Entity Framework.
For those dismissing ORM's...Domain Modeling is where things are going. Its not fine to just stick with the old Active Record way of doing things unless you want to get left behind. It has nothing to do with n00bs not being able to understand data structures...
>This publisher seems to have come out of nowhere
Not quite - when Wrox folded (the big red books with programmers on the covers are now actually published by Wiley) and the royalties and fees owed to many authors and staff were written off, the guy who owned it went a few hundred yards down the road (back to the office where Wrox originally started) and founded Packt, presumably with money siphoned out of Wrox before the end.
Their business model seems to be to get contributors to open source projects to write for them for below market rates with the promise that their projects will benefit from the exposure of a book.
It seems like every other Slashdot book review is for a Packt book nowerdays. I suspect "RickJWagner" is on the Packt staff. If not, then he has an unhealthy obsession with them as they seem to be the only books he reads.
I live with the pain of using Hibernate (Java version) every day. May I suggest something sane instead: use SimpleORM!
Read this white paper: http://www.simpleorm.org/sorm/whitepaper.html
Even if you don't end up using it the whitepaper will give you some good insights into why not to use Hibernate
Thank god for all the bitching scripting "programmers" that despise ORMs and would rather use hand-written SQL statements. You keep the rest of us happily, steadily employed.
Are you one of those idiots who think C/C++ make up 99% of the job market, and that Java and C# aren't used at all? You realize you can write web services with C#, right? I'm guessing the answer to those questions is yes and no, in that order.