SQL Zone is brought to you in partnership with:

Jason has posted 2 posts at DZone. View Full User Profile

Win Your Copy: Java Persistence with Hibernate

  • submit to reddit
Published by: Manning
ISBN: 1932394885

Reviewer Ratings




Buy it now

One Minute Bottom Line

Whether you are new to Hibernate and want to dive into your first project or are a Hibernate guru and need a reference manual to remind you of how to implement a conversation, this is the right book. The authors have really covered all the bases. Anything you want to know about Hibernate is in here.

I highly recommend this book to anyone needing to get started with Java and Hibernate!


This book is divided into 3 parts with 2 appendices.

Part 1: Getting Started With Hibernate and EJB 3.0

This is the foundation for understanding how Hibernate works. The most relevant part for me was selling me on "why Hibernate?" I've always been a "do it yourself SQL person". In chapter 1, I was sold. Forget ease of use. Forget performance and caching. The integration between Hibernate and EJB and the fact that JPA is becoming the standard was enough to make me take notice that this is a technology you cannot ignore if you are going to develop Java applications that use a relational database.

Chapter 2 helps you get going on your first project. Everything from creating the database to a preview of Hibernate annotations is covered.

Part 2: Mapping Concepts and Strategies

In an object-relational mapping solution you will soon find that how you map your objects in code is a lot of the challenge. While about 80% of the mappings that you do will be very simple, you will likely have some mappings that are more challenging and problematic.

Chapter 4 starts you out and delves into the simple to the advanced mapping topics you will need. This is a fantastic chapter and was probably the most useful one for me.

Chapter 6 covers mapping collections and is an essential foundation if you are going to be doing any sort of joins or other derived data sets in your mappings.

Chapter 7 goes into how those joins are accomplished in your mapping.

Chapter 8 covers what to do if you need to use an existing or legacy database. This is not just a "how do I use Hibernate with my existing schema" but it also explains some improvements that Hibernate can make to get more out of that legacy system. Very nice! Because we don't always get to start out with a clean slate!

Part 3: Conversation Object Processing

This was a rather new concept to me. I have always been used to managing transactions and session data myself. But the concept of a "conversation" was something that I have never considered until reading this section.

In chapter 10 transactions and concurrency are covered in dept. I was familiar with this part.

However, in chapter 11,  the conversation is introduced. The conversation is more than just using session data. It can include several transactions and other user actions.

If you want a lesson in efficiency and how to manage large sets of data, then chapters 12 and 13 are for you. Dynamic data filtering and caching were the most useful and interesting to me and if you are going to work with large data sets, I highly recommend spending some time understanding the concepts given here.

The rest of this part of the book and appendix A are all about query language, querying and the API and how they are used. This is a proportionately large section in the book and rightfully so because understanding this is fundamental to understanding Hibernate. After all, Hibernate must, at some point, create a query that is native to the database it is used with. Debugging such a thing can be difficult if you are unfamiliar with query concepts.

There is also part in chapter 16 that covers unit testing Hibernate code. If there is a negative aspect of this book, this is it. I don't think enough emphasis was given to this topic. However, unit testing is a fairly domain specific thing and I'm not sure that it could (or should) be covered in too much depth. After getting to this point, you should take what you have learned about Hibernate and apply your own knowledge of unit testing.

Appendix A: SQL fundamentals

This appendix is just that: fundamentals. It gives you enough information to understand what SQL is and some fundamental concepts but is in no way meant to be (nor could it be) a comprehensive overview of SQL. If you want an in-depth study of SQL, grab a database like MySQL and the manual and get to it!

The book index is probably your best friend when it comes to reference information especially when you have an idea about an annotation that you want to use but can't quite remember where it was or how it was spelled, etc. I loved the index to this book! What a huge help!

For more information about the author and this book click here.

Click here to see all 46 DZone Refcardz and cheat like a PRO! 


Published at DZone with permission of its author, Jason Kilgrow.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Paul Wallace replied on Wed, 2009/03/25 - 11:33am

interested in reading more about "conversations"

Bertrand Gillis replied on Wed, 2009/03/25 - 11:53am

This is the BEST book for hibernate.

Better than hibernate in action and other books.

More real world illustrative examples will be greatly welcome.

Diego López León replied on Wed, 2009/03/25 - 12:04pm

As ORM, Hibernate is the best option, for performance, for documentation, for low learing curve and for extensibility of the platform. Is really well designed and really easy to integrate with existing legacy applications. Good to see a new book on this topic.

Álvaro Martínez replied on Wed, 2009/03/25 - 12:13pm

There is no alternative to Hibernate for "usual" projects these days. I don't even know what I'm doing using JPA in top of it since I won't use any other ORM solution (but I guess it's the right thing to do).

I'm currently using Hibernate with Scala. It's usually painless, but Scala doesn't currently support nested annotations, and that is a problem at least with JPA. All I have to do is to define these complexmappings in a hbm.xml file. Anyway, this problem should be fixed in Scala 2.8.0.

Cody A_ replied on Wed, 2009/03/25 - 12:19pm

We're using Hibernate 3.2 as our ORM for a system pushing 300+ Oracle tables. So far performance is great. I really came to appreciate the concept of ORM using Hibernate. The documentation could've been written better for those of us who aren't exactly ORM experts, but otherwise I have no complaints.

Giri Senji replied on Wed, 2009/03/25 - 12:23pm

This is by far the best resource on the subject. Its been a while since I used ORM. Now I'm trying to refresh up on the latest.

Brad Parks replied on Wed, 2009/03/25 - 12:32pm

I've used Hibernate on almost every project for the last few years and am constantly learning new things about what this powerful tool can do.  I don't know how I ever survived without it.

Tenshi Tesn replied on Wed, 2009/03/25 - 4:00pm

Been using Hibernate for last couple of years now, and I really enjoy it.

Hantsy Bai replied on Wed, 2009/03/25 - 9:18pm

I have used Hibernate in work for years. Most of the projects, I used MySQL as database and using custom JDBC DAO implementation as persistent layer , after using Hibernate, I do not care the database-specific feature and focus the business implementation. Hibernate hides the JDBC operation and SQL writing directly for client caller. It make the complex things become simple.


Sudhakar Ramasamy replied on Wed, 2009/03/25 - 10:32pm

I've used JPA and other open-source implementations. But Hibernate seems to be the most mature ORM tool in the Java space. Having this book as a handy reference would be awesome!

Milos Silhanek replied on Thu, 2009/03/26 - 2:27am

I build new big application over NetBeans Platform and I will use Hibernate to DB connection. I have some difficulties because I must wrap entity library and hibernate jars. It works as a prototype but it has not worked in application yet.

   Searching I need use for client or contract retrieval and I want to care about my problem domain only. 


Jeroen Wenting replied on Thu, 2009/03/26 - 2:50am

"This is the BEST book for hibernate.
Better than hibernate in action and other books. "

It should be better, it replaces Hibernate in Action :)
Not currently working with Hibernate, but have in the past. This book helped me out in some tight spots. Would have liked a free eBook version to come with it though, similar to what APress does with some of their biggest tomes, as it's rather hefty to carry between home and office every day. For that reason alone I wouldn't mind another copy.

Girish Ahankari replied on Thu, 2009/03/26 - 3:34am

I have worked on Hibernate for a year now, skimmed through few books and scanned few forums. Would like to review this book to see how helpful it will be for the programmer community.

Forum Prutt replied on Thu, 2009/03/26 - 4:24am

We use Hibernate for persistence at work all the time and it performs just great!

Leandro Sabin replied on Thu, 2009/03/26 - 5:39am

This is a very good book, not only for JPA and Hibernate but also persistence in general.

Todd Cosgrove replied on Thu, 2009/03/26 - 8:23am

I've used JPA and Hibernate as the persistence layer for my last few projects and I look forward to any additional information this book can provide.

Gian Franco Casula replied on Thu, 2009/03/26 - 8:31am

Thanks for the review.

In particular Chapter 8 raises my interest: not all projects are green-field and since introducing Hibernate is an option to consider some guidelines in doing so are always welcome.

Personally I would not have minded excluding Appendix A: SQL fundamentals from the book, I think someone picking up the book should think of Hibernate as the missing link between two worlds (db and code) and understand these two worlds a priori.

Andy Jefferson replied on Thu, 2009/03/26 - 8:48am

Alvaro Martinez said, "There is no alternative to Hibernate for "usual" projects these days."

Oh, there are plenty of alternatives; we aren't in the same situation as in 2002 - developers are spoilt for choice now. Many alternatives have more flexible licensing. Many are doing things that Hibernate doesn't approach. Many are faster. I'd encourage you to investigate further ...

--Andy DataNucleus

Stan Bershadskiy replied on Thu, 2009/03/26 - 8:54am

Used JPA with Hibernate implementation in my latest web application using GWT. It was interesting working with two models, one being JPA entities and the other being a stripped down GWT Bean. Would like to learn more about Hibernate and JPA

Álvaro Martínez replied on Thu, 2009/03/26 - 10:36am

Jefferson, you are right :-) . I meant there is no better alternative in my opinion, if only because of the strong community behind Hibernate -- sometimes it is more valuable than anything else, specially if your're doing weird stuff like I'm doing with Scala.

Ram Kompella replied on Thu, 2009/03/26 - 10:03am

I've been using Hibernate for almost two years , and I really enjoy it. Would love to have this book..

Kunal Dabir replied on Fri, 2009/03/27 - 1:35pm

I've been using hibernate for last few projects and i must say it rocks. In the current project we are using hibernate to load entities in Map Mode. This is such a dynamic feature that one can complete an entire project without ever having to implement the domain models java classes. I'd love to see a bit more coverage on Map and DOM modes in this book (as this is more useful than authors considered it to be). In fact, some good frameworks can be built up using these modes to provide dynamic UIs (Or is something out there already built on this?).

Jon Baso replied on Thu, 2009/03/26 - 1:31pm

We've been using Hibernate on every project for the past couple of years, from legacy databases to new designs. I think Hibernate is better suited for new development, but it still works well in legacy database situations. We've also recently started using Hibernate Search for a "one-field" google-style search into our database and it's working really well.

De ZB replied on Thu, 2009/03/26 - 2:05pm

I used Hibernate and had all sorts of problems with lazy loading of fields. Posted questions on the Hibernate forum and had no helpful replies (some abusive ones). Maybe this book would explain to me better how it works, because my opinion of it right now is not high.

Paul Szulc replied on Thu, 2009/03/26 - 3:04pm



 ... maybe it is?


I dont, know. I  would have to rread it, to tell you.

Jason Kilgrow replied on Fri, 2009/03/27 - 5:43pm in response to: Girish Ahankari

As a developer myself, I can tell you that this book has become an invaluable resource for me while developing the project that I worked on while reviewing the book. While Hibernate is not without problems, if your persistence solution is Hibernate, you can not go wrong with this book as your guide.

Jason Kilgrow replied on Fri, 2009/03/27 - 5:52pm in response to: De ZB

Just like anything else, Hibernate is not foolproof. You can still get into trouble if you do things the wrong way. The real strength of this book is that it can help you learn how to do things the right way so that you will have a good experience with the technology. I was pretty new to Hibernate when I started reviewing the book but now feel much more confident that I can put together a winning solution. I do not claim to be an expert but I feel much more knowledgable now after reading this book.

Jason Kilgrow replied on Fri, 2009/03/27 - 5:56pm in response to: Paul Wallace

Yeah! There is even a chapter on how to integrate Hibernate with Seam. I didn't read that chapter too closely because I am involved with Spring on Glassfish. But I have always wanted to check out Seam too!

Jon Baso replied on Thu, 2009/04/02 - 11:06am

did anyone win?

Wei Ling Chen replied on Thu, 2009/04/02 - 1:41pm in response to: Jon Baso

Not yet, we plan to pick and announce a winner early next week. Thanks!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.