Hibernate In Action

In the same way that we’ve been checking out web frameworks for Java, we’ve also been looking at persistence layers. Despite strong recommendations for iBatis, we’ve ended up going for hibernate, largely because “it’s what everybody else uses”… So I’m learning my way around Hibernate, aided by the Hibernate In Action book. Now the book seems quite reasonable so far at explaining why Hibernate is so damned complicated (this is my 3rd ORM I’ve used, yet it still seems weird and bloaty). My pain starts when I get to the second chapter, where the code starts.

The main problem is that the very second example comes unstuck. The first line is:

  Session session = getSessionFactory().openSession();

Where is this magical getSessionFactory() coming from? Looking it up in the index sends me to page 314, smack into the middle of the “the session façade pattern”, where an implementation that probably won’t work for me sits. Thankfully, I can spot the obvious bit:

  new Configuration().configure().buildSessionFactory();

But why on earth dont they put this in chapter 2 where it belongs? I’ve got code sitting in front of me that I can’t run, and that’s a crime.

Oh, on top of that, turning the page reveals the phrase “the code fragment prints…”. Well, it would if I had a hibernate config file to go with the mapping file that they presented. What a waste of my time figuring all this out. I’m just glad I didn’t pay for this book (work did).

Alright, turning a few pages further on we get to “Creating a SessionFactory”. That’s better. But there’s still no excuse for code samples you can’t run.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s