Hibernate in Action 220
Hibernate in Action | |
author | Christian Bauer and Gavin King |
pages | 400 |
publisher | Manning |
rating | unavoidable |
reviewer | Adrian Spinei |
ISBN | 193239415X |
summary | ORM pour les connaisseurs |
Well, I am glad to tell you that this is not just a dump of the on-line docs. The book not only gets you up to speed with Hibernate and its features (which the documentation does quite well). It also introduces you to the right way of developing and tuning an industrial-quality Hibernate application. I consider myself a pretty seasoned Hibernate developer, being familiar with the API since its 1.2 version in Q1-2002 (if I remember well the first app when we used Hibernate). However, I was proved wrong by Hibernate in Action, which describes best practices and even API features that were unknown or vaguely known to me. That is, until now.
The first chapter, in the good tradition of all first chapters in the world, is an introduction. It's a very well written introduction about why do we need ORM solutions in OO applications. The chapter explains the O/R impedance mismatch, while declaring quickly that OODB sucks (immature and not widely adopted). Wel'll also find out that EJB also sucks from a persistence point of view (for various reasons). Which can be quite a surprise knowing that Gavin is one of the authors of EJB3.0 specs. Or, on the contrary, this will explain a lot of things in the new EJB specs.
Now that we have cleared the "why Hibernate" issue, let's continue to the second chapter. Which - tradition obliged - is a "Hello, world" and a "Let's get started" chapter. Here you go: almost 50 pages later you should be able to write simple Hibernate-based persistence layers and integrate within an application server, like for instance ... Jboss ! Humm, well, why not ? They are sponsors of the Hibernate project, after all.
In the 3rd chapter, our fresh knowledge will be put to good use by starting the development of an online auction application called CaveatEmptor. This app will follow our reading progression and will grow bigger and smarter chapter by chapter. But for the moment, we are at the inception phase. What gives: a little bit of analysis, a stylish class diagram of the domain model and the resulting mapping file. And if you thought (based on 2nd chapter) that the mapping file is very intuitive and simple, you're in for a big surprise -- it is, indeed, intuitive and simple! Quite bizarre for an open-source project. As a matter of fact, the mapping file is one of the pivotal elements of Hibernate, since it addresses directly the O/R impedance mismatch, a recipe for transparent linking your POJOs and the constrained relational model. No wonder that a big part of this chapter is aimed at explaining why and how the mapping works in Hibernate. You'll see how class associations and inheritance translate at the metadata and mapping level. You'll start to understand the things that you took for granted in the previous chapter and you'll have that pleasant "uuh, I see" chain reaction. Hold on, it's just the beginning.
Because chapter 4 is going to explain once and for all the lifecycle of persistent object in Hibernate, their behavior from a persistence point of view as well as the available fetching strategies. And if you thought you already knew everything by heart from the documentation ... well, maybe you do know everything by heart. Nevertheless, it's very well synthesized in chapter 4 and I'll recommend it anytime to a coworker eager for Hibernate knowledge.
In the next chapter (the 5th) the rollercoaster slows down a bit. That is, if you already know the behavior associated with the four possible isolation modes in transactions, what are the different types of locking, what (the hell) MVCC means and the importance of transaction scopes. Chances are you already know some of this stuff quite well, but everybody needs a refresher from time to time, especially when it's well explained and when it comes with versioning and caching (1st and 2nd level) in Hibernate as a desert. By the way, I thought that OSCache supports clustering, not only SwarmCache and JbossCache, as stated in the book. There's even a thoroughly explained example of using JbossCache as a level 2 clustered cache for Hibernate, but it shouldn't be too hard to convert to other types of caching systems.
Now, if I were the author of the book, I would have placed chapter 6 before chapter 5. But I am not the author, which is quite fortunate for you dear readers since Christian and Gavin are much more competent than me at writing books about Hibernate (and probably at some other unrelated domains). They have decided to go back to mapping in chapter 6, after the short transaction/caching intermezzo. Well, they should know better... it's time for a serious dose of advanced mapping. This chapter is attacking interesting subjects such as custom mapping types (simple or composite) and (finally) the mapping of collections. Special guests stars: the whole gang of "sets, bags, lists and maps", together with explanations about their relational equivalent (associations, associations and associations !). Oh and yes "polymorphic association" (section 6.4.3) - I wasn't even aware that Hibernate is able to do that... guess I'm not that 'seasoned' (as a Hibernate developer) after all.
The 7th chapter is about "Retrieving objects efficiently" : about 45 pages for the 'retrieving' part and 6 pages for the 'efficiently' part. Fair enough ! You'll learn how to master basic HQL queries (parameters, pagination ...). You'll get a grip on the query by criteria API, as well as on advanced stuff such as dynamic queries, filters, subqueries and native SQL (very powerful). At the end of the chapter there's the Hibernate-specific solution for the n+1 selects problem, query caching and result iterators.
Following this wealth of useful knowledge, the 8th chapter starts a bit dry. Nevertheless, after a short introduction about Hibernate in managed environments, you'll find yourself again in the land of advanced programming techniques : application-level transaction implementation ! This is mostly new stuff (at least for me) - a great collection of best practices for transactional behavior management in industrial-quality apps. Somewhat unrelated but still interesting, the chapter ends with legacy schemas integration and a smart implementation example for audit logging.
The 9th (and last) chapter is about the round-trip development in Hibernate using the classical toolset : Middlegen and/or hbm2java and/or XDoclet. All the available techniques are presented in a very detailed, step-by-step manner.
Wait : don't close the book, there's more ! Ignore Appendix A (a short and rather uninteresting document about SQL fundamentals - that is, if you know SQL). Appendix B contains mildly un-fascinating ORM implementation strategies pour les connoisseurs (come on guys, I'm just a dumb user). But - Appendix C is a great collection of real-world stories and by all means read them all ! Especially the last one, a treasure of hard to find knowledge (no spoilers, please...).
In the end, I have to confess that there is something truly interesting about Hibernate In Action : albeit very technical, it reads astonishingly easy - and this kind of books is unfortunately very rare nowadays. My congratulations to the authors for this excellent piece of work - it was worth the wait.
As for you dear potential reader, if you already know all the information detailed in the book, I bow before you, great Hibernate wizard.
You can purchase Hibernate in Action from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Hibernate? (Score:2, Funny)
CBV*()$#
Re:Hibernate? (Score:3, Funny)
Re:Hibernate? (Score:2)
CV@#$B
What is Hibernate ? (Score:5, Insightful)
Johnny English
Re:What is Hibernate ? (Score:5, Funny)
Dan East
Re:What is Hibernate ? (Score:2)
Shouldn't that be... (Score:2)
C'mon! "Hibernate in Action" is an oxymoron of biblical proportion.
Re:What is Hibernate ? (Score:5, Informative)
Perl equivalent is... (Score:2)
Re:What is Hibernate ? (Score:2)
--
Re:What is Hibernate ? (Score:2)
Re:What is Hibernate ? (Score:5, Informative)
Re:What is Hibernate ? (Score:5, Informative)
Actually, it does matter which comes first. Hibernate works best (best defined as most clean, simply) if you have the luxury of a well normalized schema where every table contains a surrogate key. Obviously, if you're working from a clean sheet this is an worthy design choice, relatively easy to satisfy.
However, if you are working with a pre-existing design and you can't retrofit surrogate keys, you're in for a lot of additional leg-work with Hibernate. Getting Hibernate to function with composite keys forces extra coding and imposes limitations. This was my experience 9 months ago when I had a look at Hibernate for an "enterprise" application that must work with vendor schemas.
I don't fault Hibernate; persistence is hard. Mapping an object from RAM to relational storage is much easier when you have a simple 1-to-1 relationship between objects and integers. Working well only with simple surrogate keys is not unique to Hibernate by any means. In principle you're correct; it doesn't matter which comes first. In practice, if you're dealing with composite keys or any form of denormalization you're in for a lot of pain.
Re:What is Hibernate ? (Score:2, Informative)
Usually, problems with mapping existing database schemas to Hibernate arise from the shorcomings of the database and not Hibernate. Oracle's CLOBs and BLOBs are a good example of this, as the methods exposed by the JDBC interface do not work properly and methods from Oracle's CLOB and BLOB classes must be used directly, breaking transparency and forcing the developer to do add
Re:What is Hibernate ? (Score:2)
Re:What is Hibernate ? (Score:3, Informative)
Hibernate is tempermental at best and broken at worst. The biggest problem is it has it's own special language called HSQL which gets converted into SQL at runtime.
HSQL is supposed to be database neutral. However, things don't work the way they are supposed to all the time. Specifically CLOB/BLOBs on DB2 for OS390 crash the OS390 JVM. Other things fail (sometimes silently) in unexpect
Re:What is Hibernate ? (Score:2)
Re:What is Hibernate ? (Score:4, Informative)
This was grabbed off www.onjava.com:
Hibernate will help us to painlessly store the data in permanent storage without too much hassle about choosing the kind of storage, installation, or configuration. Hibernate allows us to store any kind of objects; therefore, our application does not need to know that its data will be persisted using Hibernate. Of course, everything mentioned here can be applied in the opposite direction: fetching already prepared objects from a storage is now nearly trivial. Updating and deleting data is also available.
Judging by their inaccessible website, Hibernate is what they do best.
The overview tells us nothing (Score:5, Insightful)
Re:The overview tells us nothing (Score:5, Funny)
Re:The overview tells us nothing (Score:2)
Three Letter Acronym...
=)
Re:The overview tells us nothing (Score:2)
Three Letter Acronym... just in case you weren't kidding.
For the more likely case that this was not straight: the proper quote was "What's a Nubian?"
Re:The overview tells us nothing (Score:2)
Re:The overview tells us nothing (Score:2)
if you've got a problem with ORM as a TLA then you've probably got a problem with CPU as a TLA as well..
jesuxfscking chkdisk.
Re:What is Hibernate ? (Score:2)
A 400 page manual? (Score:5, Funny)
Jeez, with a manual that big it should be named coma.
Hibernate is good, but I am using Prevayler more (Score:5, Informative)
However, for my Java consulting business, Prevalyer [prevayler.org] is definitely my new "secret weapon". With a little care, it is easy to set up your POJO classes so that you can add class attributes without breaking your persistent Prevayler object store. Using Prevayler reduces development time. Good stuff.
Re:Hibernate is good, but I am using Prevayler mor (Score:5, Insightful)
I have seen many applications where a developer will pull a list of objects out of a database and only use a small percentage of what was pulled. This was caused by a heavy persistence layer abstracting what was happening, and a developer that didn't care to find out.
I seem to be in the minority with this view though. Automated persistence is quite trendy.
Re:Hibernate is good, but I am using Prevayler mor (Score:4, Insightful)
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
Re:Hibernate is good, but I am using Prevayler mor (Score:3, Insightful)
Don't forget, many modern developers haven't yet figured out that abstraction and performance are in an inverse relationship.
Re:Hibernate is good, but I am using Prevayler mor (Score:4, Funny)
I just made me sick
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
On the other hand, that might not be the correct tradeoff in a desktop application.
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
let's spend 2 years rewriting all business logic in assembler...
Re:Hibernate is good, but I am using Prevayler mor (Score:4, Informative)
Also: with Hibernate, you do have control over how much of a row of data you actually retrieve since you specify the mapping that you want in an XML configuration file.
Do try Prevayler however: for some applications it really is a great tool. I especially like it for web applications where most data access is read only: caching objects in memory really speeds things up.
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
Re:Hibernate is good, but I am using Prevayler mor (Score:3, Informative)
"I went into this knowing very little about ORM, and even very little about databases. One of my first tasks was to go out and buy a book to learn SQL properly. All my understanding of the problem comes from what our users have taught us over the last two years."
Sigh... basing a product on secondhand experience from users who probably have never even learned what the relational model is really about.
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
Re:Hibernate is good, but I am using Prevayler mor (Score:5, Funny)
However, for my Java consulting business, Prevalyer is definitely my new "secret weapon". With a little care, it is easy to set up your POJO classes so that you can add class attributes without breaking your persistent Prevayler object store. Using Prevayler reduces development time. Good stuff.
Good Lord.
This post, while informative, just makes me want to go to sleep. Or quit my job. Or both.
Maybe I chose the wrong career.
Are Java class mappings to databases really all that exciting?
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
Re:Hibernate is good, but I am using Prevayler mor (Score:2)
Well, evidently not -- since the author was excited about Prevlayer, which isn't a mapping to a database.
-Billy
Re:Hibernate is good, but I am using Prevayler mor (Score:3, Insightful)
Anyway, the point is the site doesn't do anything to elucidate the limitations on ACID compliance, querying capabilities
What is it? (Score:3, Insightful)
Re:What is it? (Score:2)
A thread of macslash.org [macslash.org] about ReCycle generated some pretty funny posts based on no explanation of program function [macslash.org]. It also generated some of the "it's so great that if you haven't heard of it your not worthy to use it" comments.
By the way, if you've never heard of Hibernate... (Score:5, Informative)
Hibernate is an API for Java that uses Java Beans (get() and set() methods for all properties) to create, read, update and delete rows from a database. It's really cool. It's sometimes called JDO (Java Data Objects) but it's a dangerous association because of the Sun Reference Implementation of JDO, which is its own specification. Hibernate is different.
Re:By the way, if you've never heard of Hibernate. (Score:2)
(Ok, maybe it's not ironic. After all the flaming from irony-obessed pedants, I have no idea anymore. But it's at least as ironic a rain on your weddi
Re:By the way, if you've never heard of Hibernate. (Score:2)
book better than review, I hope (Score:5, Insightful)
-russ
Re:book better than review, I hope (Score:2)
whaa? (Score:2, Funny)
MOD PARENT UP (Score:4, Insightful)
You're right, there is no information in the article. It doesn't even tell us what Hibernate is. The blather is also peppered with undefined acronyms - ORM, POJO, HQL.
And some idiot moderator modded parent down as a troll. Sigh. It's not a troll, it's a valid and accurate criticism of a really crap article. Crap is, unfortunately, becoming the Slashdot-article standard.
Why hibernate? What's hibernate? (Score:4, Funny)
Now that we have cleared the "why Hibernate" issue,
Yeah... Cleared that right up. ORM? O/R Impedence? OODB? EJB? Little help here?
Re:Why hibernate? What's hibernate? (Score:2)
Re:Why hibernate? What's hibernate? (Score:3, Informative)
I hope that helped.
Re:Why hibernate? What's hibernate? (Score:2)
Pardon my ignorance... (Score:3, Funny)
Rather than sharing my theories about a top-secret-yet-LGPLd government project to develop object-oriented Java-based SQL/graphics library that will allow us to train secret UFO pilots to defeat an invasion of alien accountants, would someone care to fill me in? I would be forever in your debt.
Re:Pardon my ignorance... (Score:2)
No, I'm not new here... (Score:2, Flamebait)
Curious why there's not more. (Score:3, Insightful)
OSS Coders tend to have the fantastic attitude of always improving whats been written before, of making it better & better, revising, patching, rewriting, until an application becomes so damned useful there doesn't seem to be any other realistic choice.
All well and good when it comes to coding - but where are all the documentation geeks to do likewise?
There's more (Score:2)
It depends on the popularity... if a library becomes very widely used, its documentation will improve by itself. GTK documentation had been almost nonexistent during the 1.x days (just a tutorial), but now it is mostly acceptable
What's in a name? (Score:2, Funny)
Based on the info in the title, I concluded that the project did nothing (after all, a successul implementation of hibernation just sits there.) This caused me much confusion, resulting in me mistaking salt for sugar, and baking soda for non-dairy creamer....
...Remember kids, think before you p
Re: (Score:2)
Another project with a lot of Documentation (Score:4, Funny)
http://www.r-project.org/ [r-project.org]
This is an amazing stat program that is open source with a lot of documentation backing it up.
Some of the documentation you can download:
An Introduction to R (approx. 100 pages, 650kB)
The R Reference Index (approx. 2300 pages, 12MB)
Also, under their contributed documentation section, they have the documents sepearted by "Documents with more than 100 pages" and "Documents with less than 100 pages".
Is there a doc in the house? (Score:4, Insightful)
Re:Is there a doc in the house? (Score:2)
I am a tad surprised (Score:2, Interesting)
Re:I am a tad surprised (Score:3, Informative)
It sounds like this may come as a complete surprise to you, but not everybody is a Java programmer. Why should non-Java programmers be expected to know about a Java-only tool?
Re:I am a tad surprised (Score:2)
Re:I am a tad surprised (Score:2)
Dude (Score:3, Funny)
Re:I am a tad surprised (Score:2)
After reading some of the comments on this article, I'm thinking this might be a bit of a stretch.
Another example of good documentation is R (Score:2, Redundant)
The program is GPLed, and shows that excellent documentation is possible, if enough people.
Re:Another example of good documentation is R (Score:2)
At home, I'm using whatever version of LaTeX is on Debian testing. Here at work, I use MikTeX. I know that the Debian version handles the .ltx extension just fine, but I'm not sure about the windows version here at work.
Best thing since sliced bread (Score:5, Informative)
Okay, I haven't RTFA, but the poster should also have made mention of Spring, which works hand in hand with Hibernate. Spring basically is an Inversion Of Control (IOC) framework, that allows you to define Hibernate transaction and session contexts. Spring also offers a great MVC layer, but one does not have to use that. If one chooses to just use Spring as an addition to Hibernate, one can look at Spring's additional functionalities as needed. Spring also offers Oracle BLOB/CLOB support by offering a customized OracleClobHandler - Oracle ONLY supports its propietary CLOB objects and won't accept java.sql.Clob objects via Hibernate.
Generally, Hibernate is very non-intrusive and gives you the opportunity to write JDBC code alongside with your Hibernate code (which is super-elegant and abstracted the way it should have been done a long time ago). So, it can be slowly folced into an existing project without having to refactor any legacy code.
The Hibernate user group is a bit rude to be quite frank - I've tried to post some questions in the dev group and got pretty angry replies. The 'beginner' group was not very helpful, so I had to google for answers. Of course there's the book, and I would strongly recommend to get it, since it is one of the major revenue sources for those Hibernate contributors. We want open source, but we can't expect to get everything for free, right?
My first exposure to Hibernate was through the Appfuse framework [raibledesigns.com], which is an excellent J2EE kickstart project, complete with ant built, Xdoclet, Hibernate, Spring, the works. I was even able to use XDoclet tags inside my Java beans, relieving me of having to write my Hibernate definition files by hand! It really doesn't get much easier than that. For anyone wanting to give Hibernate/Spring a try, I recommend to download the latest version of appfuse and give it a try - it's a liberating experience. The biggest kick I got was being able to seamlessly switch my project from Oracle over to MySQL by simply changing a few environment variables - I mean, how cooler can it get?
Re:So if it takes a few weeks to learn... (Score:3, Informative)
Sufficient docs rare? (Score:4, Insightful)
a 7000-word document on configuring ALSA drivers
a 400,000-word document on using MySQL
a 700,000-word documentation set for Perl (just the core, not counting add-on modules)
6.5MB of Kernel docs
27MB of Gnome help
Nope, that's not a particularly outstanding trait. If he had talked about this documentation being well integrated with other, related documentation-sets, then I'd find that interesting (rarely is this the case in open source software), but it doesn't sound like it is.
What their server is doing right now.... (Score:4, Funny)
Hibernate in Action (Score:3, Funny)
So, I'm the only one, huh? (Score:3, Insightful)
Actually, this entire article is proof of how...
To the people at hibernate.org [hibernate.org]: you should be ashamed.
Re:So, I'm the only one, huh? (Score:2)
It's an old and boring disk alright, so not much use to start on that again.
And no, I won't even start picking from the many dozen software names that don't have anything to do with their goals. Because I just don't really care. If you give me a usable tool you can call it pumpkin-pie-2k if you wish. It's your choice.
Hell, does your name have
Where is that Murphies law article (Score:2)
The doco is very good but I think some of it needs updating. A lot of it still refers to the hibernate.properties which I believe is deprecated in favour of xml configuration. For example I still haven't been able to get the SqlExport ant task to work with the xml conf even following the documentation - however I only tried for about 10 mins. I wil
Re:Where is that Murphies law article (Score:2)
Same here. Sucks big time.
Might as well read some more
Hibernate's either been slashdotted... (Score:2)
Slashdot rewards good LGPL project.... (Score:2)
Hibernate+Spring = Power (Score:2)
Hibernate+Spring+Tapestry = MORE Power (Score:2)
Spring allows you to put together your UI code, your persistence code, and your business logic together, without the need to tie any layer to the other ones.
Re:Hibernate+Spring = Power (Score:2)
POJO = Plain old Java Object (just data, getters and setters)
IOC = Inversion of Control - essentially you inject control into the container rather than coding it directly. This is a design pattern embodied by the Spring framework that lets you inject the appropriate control as long as you follow certain standards so that practically everything can be swapped out later for different implementations
Re:Hibernate+Spring = Power (Score:2)
aop = Aspect Oriented Programming. This is an extension of the OO language to allow crosscutting or writing logic across many or all of your classes rather than doing the same type of thing in each object. Great for logging, security and for modifying the behavior of packaged code that you don't want to open up or cannot open up. As long as you have the jar and a javadoc you can alter the classes provided.
Where's the introduction to the review? (Score:2)
It's ironic that the reviewer acknowledges that introductions are a "good tradition" but then fails to write an good introduction himself . . . I like many had no idea what Hibernate is until I read some of the posts by gracious /.'ers that took the time to post a description of Hibernate. Additonally isn't it good wri
400 pages about a snooze function for laptops? (Score:2)
Its good, but look at JDO as well (Score:2)
Re:Its good, but look at JDO as well (Score:2)
I hope someday the EJB stuff becomes easier to deploy, maybe they can take some ideas from Spring, to allow for more container-ind
Re:Its good, but look at JDO as well (Score:2)
It isn't. It has fundamental differences - cache management is different, there are many more object cache states (e.g. hollow) than in Hibernate.
The "new" query language that comes with JDO 2.0 is based on HQL (Hibernate Query Language). They did this because Hibernate is the most popular Java ORM out there, and this time I think it was a good decision to base the new standard on an existing open source framework.
There is no new query language with JDO 2.0 - its
OT: Agila and BPM (Score:2)
http://www.infoworld.com/article/04/10/04/40NNb
Re:the article (Score:2, Funny)
Maybe if you take a long nap the site will be back.
Re:So what is it? (Score:3, Informative)
I've been using this for quite a while, coupled with Spring [springframework.org] you can write a lot of robust reusuable objects, if you utilize java's OO design methods.
Re:Hibernate? (Score:3, Informative)
Re:Still too heavy (Score:2)
That's why I use tools that do all that for you. Hibernate comes with a bunch of them, or you can use one of the excellent Eclipse plugins.
Re:Sad news: Christopher Reeve dead at 52 (Score:2)
Say... what are you insinuating he was doing with those beads?