Hibernate Quickly, Manning

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
  Title:  Hibernate Quickly
  Author(s):  Patrick Peak, Nick Heudecker
  Edition:  Manning Publications; 1st edition (August 1, 2005)
  Format:  Paperback: 220 pages
  ISBN:  1932394419
  Overall Rating:  Image:stars4H.gif The Bottom Line
C# Online.NET:Reviews: Book Reviews  •  Educ./Train. Reviews  •  Software Reviews  •  Top 10 Books

Contents


C# Online.NET Book Review

Hibernate is a popular, open source, Object-Relational (OR) Mapping tool in the Java Community. For .NET developers, there is NHibernate. Hibernate is designed to bridge the object-relational gap or "impedance" mismatch which requires an object to be mapped to a table row in order to be persisted.

Hibernate Quickly comes on the heels of the hugely successful Hibernate in Action book. But, whereas Hibernate in Action aims to be a comprehensive introduction and tutorial, Hibernate Quickly is designed to teach you only the 20% of Hibernate that you will use 80% of the time—the so-called "80-20 Rule".

In other words, this book's purpose is to get the developer up and running with Hibernate quickly. The book is an easy read; because, it presents step-by-step instructions for getting started using Hibernate. In addition, examples and diagrams (ER, UML) abound. The writing style is conversational but no nonsense. I love the font which is large and—well—friendly.

The book follows Hibernate in Action by unfolding a single example over the course of the book. During this evolution, the reader will cover concepts—one-to-many, many-to-one, and many-to-many mappings—, basics, and some advanced features—caching, cascading, lazy-loading, and transaction management —of Hibernate as each is applied in turn to the example.

The book employs many pedagogicaly sound—though informal—practices such as repeat with variation, that is, explaining concepts more than once, but in slightly different ways to avoid being repetitious. The various topics flow quite naturally from the basic to the more advanced.

Hibernate is rarely used on its own without other open source technologies. Thus, the book introduces the high level integration of Hibernate with DBUnit, JUnit, Spring, Struts, Tapestry, WebWork, and XDoclet. Unfortunately, JBoss integration is outside the scope of the book.

An entire chapter is given over to the new features of Hibernate 3.0. But, the relevant differences between versions 2 and 3 are sprinkled throughout the text.

This book would be a great investment for developers who either want to begin to use OR mapping or who need to integrate Hibernate into their current projects. However, once you do get up and running with Hibernate, you may need a second book—such as Hibernate in Action —to take you into more advanced features, more involved design issues, and more complex scenarios. The reader should already be familiar both with object-oriented programming (OOP) and with relational database technology.

All of the source code examples are in the Java language.


Bottom line

Hibernate Quickly is a useful overview and introduction to using Hibernate with various other open source packages for first time users.

Related titles

Other reviews

"If you want to learn Hibernate quickly, this book shows you step by step."
     —Sang Shin, Java Technology Architect, Sun Microsystems

From the back cover

Positioned as a layer between the application and the database, Hibernate is a powerful object/relational persistence and query service for Java. It takes care of automating a tedious task: the manual bridging of the gap between object oriented code and the relational database. Hibernate Quickly gives you all you need to start working with Hibernate now.

The book focuses on the 20% you need 80% of the time. The pages saved are used to introduce you to the Hibernate "ecosystem": how Hibernate can work with other common development tools and frameworks like XDoclet, Struts, Webwork, Spring, and Tapestry.

The book builds its code examples incrementally, introducing new concepts as it goes. It covers Hibernate's many, useful configuration and design options, breaking a complex subject into digestible pieces. With a gradual "crawl-walk-run" approach, the book teaches you what Hibernate is, what it can do, and how you can work with it effectively.

What's Inside

  • Writing mapping files and creating associations
  • Hibernate with XDoclet, Struts, Webwork, Spring, and Tapestry
  • Querying persistent objects
  • Using web application architecture
  • Testing with JUnit and Ant

About the author(s)

Patrick Peak is the CTO of a firm that emphasizes open source frameworks and tools for competitive advantage. He lives in Arlington, Virginia.

Nick Heudecker has large scale development experience with projects for Fortune 500 clients, the media, and government. He lives in Chicago, Illinois.

Table of Contents (abbreviated)

1 Why Hibernate?
2 Installing and building projects with Ant
3 Hibernate basics
4 Associations and components
5 Collections and custom types
6 Querying persistent objects
7 Organizing with Spring and data access objects
8 Web frameworks: WebWork, Struts, and Tapestry
9 Hibernating with XDoclet
10 Unit testing with JUnit and DBUnit
11 What's new in Hibernate 3
Appendix: The complete Hibernate mapping catalog

About this book

Hibernate is a solid, productive Object Relational Mapping (ORM) tool that lets developers think and work with objects rather than tables and columns. It has grown over the years, been used by many developers, and has gone through three major versions. This book's goal is to make you productive with Hibernate.

Hibernate Quickly is a gradual introduction to the features of Hibernate, covering the latest version, Hibernate 3. Each chapter introduces a series of concepts that form a foundation for the next chapter, but should illustrate those concepts completely. We set out to write the book we would have liked to have when we first learned Hibernate. We both think that studying good code examples is one of the best ways to learn, so we included as many as we could. We also wanted to make our own reference, a book we could have on our desk and turn to when we forgot just how that one mapping needed to be written.

Developers don't work with Hibernate in a vacuum. In addition to standard Java, developers often use Hibernate with a host of other third-party (often open source) tools and libraries, including J2EE (web applications); build tools like Ant; unit-testing frameworks like JUnit; and frameworks like XDoclet, Struts, WebWork, Tapestry, and Spring. This book shows how Hibernate fits into your development projects by demonstrating how these third party tools can be integrated with Hibernate. Because this book is about Hibernate, and we didn't want it to be 1,000 pages long or weigh as much as a battleship, we assume that developers are partially familiar with the third-party libraries with which they want to integrate Hibernate. We provide some introduction, so you should be able to follow along if you've used, say, Tapestry; but you should consult Manning's In Action series for more details about those tools.

Roadmap

Hibernate Quickly is logically divided into two parts. The first half of the book introduces the core concepts and features of Hibernate. The second half puts Hibernate into context by showing you how to integrate it with a number of open source tools and frameworks.

Chapter 1 is both a justification and an introduction. It covers the reasons why Hibernate is useful, and it compares and contrasts Hibernate with JDBC. It also covers the basics of what object relational mapping is and provides an introduction to how Hibernate's particular brand of persistence works.

Chapter 2 is the project kickoff. It covers setting up a Hibernate project and using Ant, an open source Java build tool. It shows you where to find both Ant and Hibernate and how to organize your project. We also discuss setting up and integrating a database, MySQL. By the end of this chapter, you should have a solid foundation for your project to build on in the subsequent chapters.

Chapter 3 is about the core concepts of Hibernate. It covers mapping files, configuration, and the essential classes developers use to persist and find objects from the database. Finally, this chapter touches on a few more advanced topics like inheritance, caching, and transactions.

Chapter 4 discusses relationships. Specifically, we cover in detail two of the most common relationships between persistent objects: many-to-one and components. This chapter also explains how to generate your database from Hibernate mappings using the SchemaExport tool.

Chapter 5 covers collections and custom types. Hibernate allows you to use basic java.util collections classes to express both one-to-many and many-to-many relationships between entities, and we show how to map and use them here. In addition, we demonstrate both how and why you can use Hibernate's custom types, which let you define new datatypes that can map to database columns.

Chapter 6 discusses finding objects. Hibernate uses a SQL-like query language that allows you to express queries using classes and properties rather than tables and columns. This chapter covers Hibernate Query Language's (HQL) syntax and usage in depth, including parameters, joins, from/select clauses, and projection. So that you can test your HQL, the chapter also touches on Hibern8IDE, a tool that lets you rapidly test and try your queries.

Chapter 7 is about patterns and architecture. We show you how to better organize your project with a few patterns like the Data Access Object (DAO) and Layer Super types. We also explain how to introduce a popular application framework, Spring, into your project. Spring integrates extremely well with Hibernate; it streamlines the DAO pattern along with some of the productive boosting features.

Chapter 8 discusses "webifying" your Hibernate application. We cover the basics of the Model View Controller pattern; and we build our sample application, the Event Calendar, using three open source web frameworks. The same application is written three times using a similar core architecture but integrated with Struts, WebWork, and Tapestry. Our intent is to show the general principles you need to consider when writing Hibernate applications for the Web.

Chapter 9 covers code generation with XDoclet. Until JDK 1.5/Java 5.0 becomes more widely accepted, Hibernate developers can either hand-write their mapping files or, better yet, use XDoclet to generate them. This chapter shows you how to do the latter. We go in depth to show you how to set up, configure, and generate mapping files for single objects, many-to-one, components, and collections. In addition, we explain how to generate your configuration files, hibernate.cfg.xml, using XDoclet.

Chapter 10 is about testing. It shows you how to use two tools, JUnit and DBUnit, to verify that your Hibernate application works as expected. We cover the general principles of unit testing and how to apply them to testing a database.

Chapter 11 discusses Hibernate 3. It's a brief guide for those who are familiar with Hibernate 2 and want to know what's new. This chapter covers the important new features, including filters, mapping file improvements, dynamic classes, and the new persistent event model.

The appendix is the reference we wanted for ourselves. It's a complete reference guide to all the common relationships that Hibernate allows. For each relationship, the appendix shows an object model, table models, Java classes (with XDoclet markup), and the resulting mapping file.

Who should read this book?

In short, Java developers who work with databases. More specifically, we aimed this book at two main groups of developers:

  • Developers who are new to Hibernate and who want a step-by-step guide to getting started painlessly
  • Hibernate intermediate/expert users who want to learn how to integrate Hibernate into their existing projects and make it work with all the other tools they already know

We assume you're familiar with basic object-oriented programming techniques as well as the Java language. We discuss a lot of third-party tools, like Ant and XDoclet, but no in-depth familiarity with them is needed. Because Hibernate builds on JDBC and uses databases, it's helpful if you're familiar with SQL and how to use it to work with databases using Java.

Preface

Like many others, I started writing my own persistence framework before I discovered Hibernate. In 2002, I was working on a large business-to-business portal that underwent frequent changes. It seemed that the persistence code changed weekly, making it impossible to both maintain the SQL and have a stable system. My first attempt at a persistence framework covered a few of the basics: associations and SQL generation. When these proved insufficient for my needs, I realized the task was large and began looking at the available persistence options for Java applications. I soon decided to go with Hibernate.

Hibernate was still relatively new at the time; version 1.0 had just been released. However, it seemed the logical choice - it wasn't overly complicated and offered the features that I needed and didn't have time to implement. Hibernate also didn't require that I change my existing code to accommodate it.

I quickly became impressed by Hibernate, having used it on a few projects. In the developer community, its popularity skyrocketed with version 2.0. I wrote a well received introductory article about Hibernate for TheServerSide, and eventually received an offer to contribute to the upcoming book Hibernate in Action from Manning. Shortly after that, Manning asked if I would be interested in writing another, complementary book on Hibernate with co-author Patrick Peak.

Patrick too had written articles on TheServerSide and we discovered a mutual interest in working together. The idea of writing a complete book loomed as a daunting undertaking but we could not resist. We decided to write the book as quickly as possible, while still publishing a first rate product.

Hibernate Quickly is the end result. Unlike Hibernate in Action which is an exhaustive reference, this book attempts to introduce the reader quickly to the core knowledge needed to start being productive with Hibernate. It uses the remaining pages to cover the larger environment that Hibernate operates in - the Hibernate "ecosystem." Hibernate 3 was released as we were finishing the writing and the book covers the newest, version 3.0 features.

Of course, we couldn't have done it alone - writing a book is a team effort and our team included reviewers, friends, colleagues, and the staff at Manning. I hope you will learn as much from reading this book as we did writing it.

—Nick Heudecker


Personal tools