Chapter 20. Hibernate

Object relational mapping (ORM) frameworks provide application developers with the ability to focus on the high-level language of the domain instead of the lower-level language of a database. Hibernate is a framework that allows you to interact with your relational data in an object-centric fashion. Hibernate’s mapping strategy allows you to convert your object-oriented schema into a database schema and vice versa. This means that as a Java programmer, you interact only with Java to get your database work done. Hibernate takes care of bridging the gap between your code and the database.

Just as important, Hibernate’s API is pluggable. Though it comes with a variety of services out of the box, whenever you don’t like one of them, you can replace it. For example, Hibernate provides a local transaction manager for single connections to a single datasource. If you need cross-database transactions, you can simply plug in the JTA instead. This pluggability allows Hibernate to be used in a broad array of situations since it plays well with its surroundings.

We wrote this chapter and the accompanying code with the beta versions of Hibernate 3.0. Some of the behavior and interfaces in the framework may change slightly by the time the book is published. Before we get started, here’s a caveat: Hibernate is a big subject, and several books are available. We recommend Better, Faster, Lighter Java by Bruce Tate and Justin Gehtland and Hibernate: A Developer’s Notebook by James ...

Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.