Award-winning Top 25 JUG!

Book Reviews

This book review was submitted by a DenverJUG member as part of the Book Review Program.

BOOK DETAILS

Hibernate in Action - ebook
Authors: Christian Bauer and Gavin King
Publisher: Manning Publications
Publish Date: August, 2004
Pages: 400
ISBN: 193239415X
Publisher's Book Description

Review Date: October, 2004
 

REVIEWER

Emilio Suarez is a Java Architect and Developer consulting for Cisco Systems. He has been working with Java and web-based applications for the last eight years, and using relational database systems for a very long time.

REVIEW

Hibernate in Action is one of the first books on Hibernate, the most popular open-source object-relational mapping framework available for Java development.

The authors are Gavin King, who is the founder and lead developer of Hibernate, and Christian Bauer, member of the Hibernate developer team and responsible for the web site and documentation. So as you will see, the information contained in this book comes directly from the source and that shows in the quality of the documentation and the detailed information on all the aspects of the Hibernate architecture.

Audience

The intended audience of the book are Java developers who work with relational database systems. It requires a basic understanding of the Java language, SQL and UML.

Ebook Format and Ease of Use

Manning provides all new books in print and "Ebook" format. I reviewed the book in the Ebook PDF format. One think that I liked about this format is its portability. I could read the book on my Windows laptop, on my Powerbook and also on my PDA, so I could read it while waiting on my kid's karate class. If you want to save some shelf space, this is a great option which also happens to be 50% cheaper than the print edition.

Summary

Having used Hibernate for about a year before any book was available, I relied mainly on the documentation available at the web site. But this book from none others than the lead developer and the lead documenter is a great introduction and reference documentation to using Hibernate. The book is organized in such a way that the concepts are explained in progressive order from very simple to more complex, and the authors take good care of explaining every detail with good examples, but most importantly with the reasoning behind what the problem are we are trying to solve and why Hibernate chose to implement the solution in this or that way.

The authors show their knowledge of relational databases and the paradigm of mapping this world with the object-oriented world of Java. This is why the book is so good at explaining Hibernate in the context of solving or providing a solution to the very complex problem of object/relational mapping.

There are other books that came out around the same time as this book and others that are coming in the following months, but this book is a very complete introduction to using Hibernate and its architecture and will become an essential reading for all developers interested in learning Hibernate.

The contents

The first chapter is used to explain the concept of ORM and why it is important. There is an interesting discussion on the different types of persistence tools used today for Java applications.

In chapter 2, the authors takes us on a quick trip to using Hibernate, showing the most trivial application ("hello world") that can be done with Hibernate, a quick explanation of the main interfaces, the basic configuration of Hibernate and some advanced configuration settings.

Chapter 3 goes deeper into the different strategies for mapping persistence classes. It shows how Hibernate is really transparent to the application model, and how it works very well with JavaBeans (POJOs). It also describes the mapping metadata and different ways of working with the XML file, using XDoclet for example, and how you can manipulate metadata at runtime. Also interesting to note here, are the sections on mapping class inheritance and associations. The authors describe the different strategies and when it is better to use them. It has been my experience that associations are one of the most tricky aspects when you start working with Hibernate.

Chapter 4 introduces the persistence life-cycle and the three types of objects: transient, persistent and detached. It also discusses the persistence manager (Hibernate Session) and how to use it effectively. It ends with a good discussion of the different strategies that Hibernate provides for retrieving objects: by identifier, by using HQL, by navigating the object graph, by using the Criteria API or by using native SQL queries. Finally a description of fetching strategies shows you how to fine-tune your Hibernate application.

Chapter 5 is dedicated to the topics of transactions, concurrency and caching. It explores the Hibernate transaction API and how it implements "transparent write behind", so that it optimizes the SQL for every session. Next it presents the isolation levels (read uncommitted, read committed, repeatable read, serializable) and how to choose the right one for your application. Then it discusses locking issues and how to work with managed versioning and how to use transactions in the scope of a Hibernate Session. It ends with a talk on caching strategies, a detailed view of Hibernate's caching architecture, including the dual-layer caching system and the different cache plug-ins you can use with Hibernate, in particular to optimize the second-level cache. It ends with a good discussion on using cache in real-life applications.

Chapter 6 moves into more advanced mapping concepts, like the use of custom mapping types, collection types (sets, bags, lists and maps), collection of components, sorted and ordered collections, one-to-one, many-to-many and polymorphic associations. Given that most database applications have different and complex relationships, this chapter is very valuable as it goes into a lot of detail to explain how Hibernate can be configured to handle all of these relationships.

Chapter 7 is a very detailed and exhaustive look into Hibernate HQL, the use of the Criteria API and the usage of native SQL to retrieve objects. It explains how to bind parameters, the usage of named queries, aliases, polymorphic queries and the usage of operators. Hibernate provides different ways of expressing joins and they are explained here in detail. There is also a good section on report queries and techniques to improve their performance. A section on advanced query techniques includes dynamic queries, collection filters, subqueries and the built-in support of native SQL that makes the use of very specialized queries work nice with Hibernate. It ends with a detailed discussion on optimizing the retrieval of object associations, the usage of iterate() queries and caching queries.

Chapter 8 discusses the overall design of Hibernate applications, how to use Hibernate with a servlet engine or an EJB container (and an interesting discussion on the DTO (anti) pattern), the implementation of the "thread-local session" pattern, how to implement application transactions, the usage of detached persistent objects, working with long sessions and working with special kinds of data schemas (legacy), triggers and composite keys. It ends with an overview of audit logging and how it can be implemented with Hibernate's Interceptor API.

Chapter 9 presents the different tools that Hibernate provides to support the development process (AndroMDA, XDoclet, SchemaExport, Middlegen and CodeGenerator) and the different scenarios (top down, bottom up, middle out, meet in the middle, roundtripping) where they can be used.

Appendix A is a short summary of SQL fundamentals. Appendix B provides a quick overview of one of Hibernate's internals: the detection of object state changes. Appendix C contains eight interesting (or bizarre) questions and the answers from the development team.