Java Persistence with Hibernate, Manning

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


Jump to: navigation, search
  Title:  Java Persistence with Hibernate
  Author(s):  Christian Bauer, Gavin King
  Edition:  Manning Publications; Revised edition (November 24, 2006)
  Format:  Paperback: 904 pages
  ISBN:  1932394885
  Overall Rating:  Image:stars4.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.

There have been two significant developments in Java persistence in the preceding year. Firstly, the release of Hibernate 3 which, now, addresses most object-relational mapping (ORM) situations faced by a Java developer. Secondly, the release of the Java Persistence API (JPA)—the new standard for ORM for both Java Enterprise Edition (JEE) and Java Standard Edition (JSE). Developed by the Java Community Process (JCP), the JPA is a part of the Enterprise JavaBeans (EJB) 3.0 Specification.

This book is a revision of the popular Hibernate in Action book. In the process, it gained some 500 pages to become the definitive work on Java persistence using OR mapping. It covers:

  • Hibernate 3.2
  • Java Persistence API (JPA)
  • Enterprise JavaBeans (EJB) 3.0

The book is organized into three parts (Table of Contents):

Part 1: Getting started with Hibernate and EJB 3.0
Part 2: Mapping concepts and strategies
Part 3: Conversational object processing

The authors are very well-qualified, knowledgeable, and have a decent writing style. However, their reach slightly exceeded their grasp in trying to cover so much ORM territory. And, chapters sometimes combine coverage of Hibernate and the JPA in ways which may leave the reader dazed and confused. In the interest of intelligibility, a better approach might be to treat the topics separately for the most part.

Warts and all, this book is—still—the best book on the market for understanding both Hibernate and the JPA. ORM beginners may want to get their feet wet first with one of the other Hibernate titles.

Hopefully, a future edition would cover the integration of the Spring Framework with Hibernate as well as the integration of the Lucene text search engine with Hibernate.

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


Bottom line

Java Persistence with Hibernate is the most comprehensive, authoritative and definitive guide, tutorial, and reference to OR-mapped Java persistence.

Related titles

From the back cover

Persistence -- the ability of data to outlive an instance of a program -- is central to modern applications. Hibernate, the most popular Java persistence tool, provides automatic and transparent object/relational mapping so it's a snap to work with SQL databases in Java applications. Hibernate conforms to the new EJB 3.0 and Java Persistence 1.0 standards.

Java Persistence with Hibernate explores Hibernate by developing an application that ties together hundreds of individual examples. You'll immediately dig into the rich programming model of Hibernate 3.2 and Java Persistence, working through queries, fetching strategies, caching, transactions, conversations, and more. You'll also appreciate the well-illustrated discussion of best practices in database design, object/relational mapping, and optimization techniques.

In this revised edition of Manning's bestselling Hibernate in Action, authors Christian Bauer and Gavin King -- the founder of the Hibernate project -- cover Hibernate 3.2 in detail along with the EJB 3.0 and Java Persistence 1.0 standards.

What's Inside

- O/R mapping concepts - Get started with Hibernate and Java Persistence - Efficient database application design - Comprehensive Hibernate and Java Persistence reference - Unmatched breadth and depth

The book ends with detailed coverage of JBoss Seam, a revolutionary web application framework for Java EE that builds on EJB 3.0, JavaServer Faces, and Hibernate concepts.

About the author(s)

Christian Bauer is a member of the Hibernate developer team and a trainer, consultant, and product manager for Hibernate, EJB 3.0, and JBoss Seam at JBoss.

Gavin King, a lead developer at JBoss, is the founder of the Hibernate project, and a member of the EJB 3.0 (JSR 220) expert group. He also leads the Web Beans JSR 299, a standardization effort involving Hibernate concepts, JSF, and EJB 3.0.

Table of Contents (abbreviated)

Part 1 Getting started with Hibernate and EJB 3.0 1
Chapter 1 Understanding object/relational persistence 3
Chapter 2 Starting a project 37
Chapter 3 Domain models and metadata 105
Part 2 Mapping concepts and strategies 155
Chapter 4 Mapping persistent classes 157
Chapter 5 Inheritance and custom types 191
Chapter 6 Mapping collections and entity associations 240
Chapter 7 Advanced entity association mappings 277
Chapter 8 Legacy databases and custom SQL 322
Part 3 Conversational object processing 381
Chapter 9 Working with objects 383
Chapter 10 Transactions and concurrency 433
Chapter 11 Implementing conversations 476
Chapter 12 Modifying objects efficiently 517
Chapter 13 Optimizing fetching and caching 559
Chapter 14 Querying with HQL and JPA QL 614
Chapter 15 Advanced query options 663
Chapter 16 Creating and testing layered applications 697
Chapter 17 Introducing JBoss Seam 747
appendix A SQL fundamentals 818
appendix B Mapping quick reference 822

About this book

We had three goals when writing this book, so you can read it as

  • A tutorial for Hibernate, Java Persistence, and EJB 3.0 that guides you through your first steps with these solutions
  • A guide for learning all basic and advanced Hibernate features for object/relational mapping, object processing, querying, performance optimization, and application design
  • A reference for whenever you need a complete and technically accurate definition of Hibernate and Java Persistence functionality

Usually, books are either tutorials or reference guides, so this stretch comes at a price. If you're new to Hibernate, we suggest that you start reading the book from the start, with the tutorials in chapters 1 and 2. If you have used an older version of Hibernate, you should read the first two chapters quickly to get an overview and then jump into the middle with chapter 3.

We will, whenever appropriate, tell you if a particular section or subject is optional or reference material that you can safely skip during your first read.

Roadmap

This book is divided into three major parts.

In part 1, we introduce the object/relational paradigm mismatch and explain the fundamentals behind object/relational mapping. We walk through a hands-on tutorial to get you started with your first Hibernate, Java Persistence, or EJB 3.0 project. We look at Java application design for domain models and at the options for creating object/relational mapping metadata.

Mapping Java classes and properties to SQL tables and columns is the focus of part 2. We explore all basic and advanced mapping options in Hibernate and Java Persistence, with XML mapping files and Java annotations. We show you how to deal with inheritance, collections, and complex class associations. Finally, we discuss integration with legacy database schemas and some mapping strategies that are especially tricky.

Part 3 is all about the processing of objects and how you can load and store data with Hibernate and Java Persistence. We introduce the programming interfaces, how to write transactional and conversation-aware applications, and how to write queries. Later, we focus on the correct design and implementation of layered Java applications. We discuss the most common design patterns that are used with Hibernate, such as the Data Access Object (DAO) and EJB Command patterns. You'll see how you can test your Hibernate application easily and what other best practices are relevant if you work an object/relational mapping software.

Finally, we introduce the JBoss Seam framework, which takes many Hibernate concepts to the next level and enables you to create conversational web applications with ease. We promise you'll find this chapter interesting, even if you don't plan to use Seam.

Who should read this book?

Readers of this book should have basic knowledge of object-oriented software development and should have used this knowledge in practice. To understand the application examples, you should be familiar with the Java programming language and the Unified Modeling Language.

Our primary target audience consists of Java developers who work with SQL-based database systems. We'll show you how to substantially increase your productivity by leveraging ORM.

If you're a database developer, the book can be part of your introduction to object-oriented software development.

If you're a database administrator, you'll be interested in how ORM affects performance and how you can tune the performance of the SQL database-management system and persistence layer to achieve performance targets. Because data access is the bottleneck in most Java applications, this book pays close attention to performance issues. Many DBAs are understandably nervous about entrusting performance to tool-generated SQL code; we seek to allay those fears and also to highlight cases where applications shouldn't use tool-managed data access. You may be relieved to discover that we don't claim that ORM is the best solution to every problem.

Code conventions

This book provides copious examples, which include all the Hibernate application artifacts: Java code, Hibernate configuration files, and XML mapping metadata files. Source code in listings or in text is in a fixed-width font like this to separate it from ordinary text. Additionally, Java method names, component parameters, object properties, and XML elements and attributes in text are also presented using fixed-width font.

Java, HTML, and XML can all be verbose. In many cases, the original source code (available online) has been reformatted; we've added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this was not enough, and listings include line-continuation markers. Additionally, comments in the source code have often been removed from the listings when the code is described in the text.

Code annotations accompany some of the source code listings, highlighting important concepts. In some cases, numbered bullets link to explanations that follow the listing.

Foreword

When Hibernate in Action was published two years ago, it was immediately recognized not only as the definitive book on Hibernate, but also as the definitive work on object/relational mapping.

In the intervening time, the persistence landscape has changed with the release of the Java Persistence API, the new standard for object/relational mapping for Java EE and Java SE which was developed under the Java Community Process as part of the Enterprise JavaBeans 3.0 Specification.

In developing the Java Persistence API, the EJB 3.0 Expert Group benefitted heavily from the experience of the O/R mapping frameworks already in use in the Java community. As one of the leaders among these, Hibernate has had a very significant influence on the technical direction of Java Persistence. This was due not only to the participation of Gavin King and other members of the Hibernate team in the EJB 3.0 standardization effort, but was also due in large part to the direct and pragmatic approach that Hibernate has taken towards O/R mapping and to the simplicity, clarity, and power of its APIs--and their resulting appeal to the Java community.

In addition to their contributions to Java Persistence, the Hibernate developers also have taken major steps forward for Hibernate with the Hibernate 3 release described in this book. Among these are support for operations over large datasets; additional and more sophisticated mapping options, especially for handling legacy databases; data filters; strategies for managing conversations; and integration with Seam, the new framework for web application development with JSF and EJB 3.0.

Java Persistence with Hibernate is therefore considerably more than simply a second edition to Hibernate in Action. It provides a comprehensive overview of all the capabilities of the Java Persistence API in addition to those of Hibernate 3, as well as a detailed comparative analysis of the two. It describes how Hibernate has been used to implement the Java Persistence standard, and how to leverage the Hibernate extensions to Java Persistence.

More important, throughout the presentation of Hibernate and Java Persistence, Christian Bauer and Gavin King illustrate and explain the fundamental principles and decisions that need to be taken into account in both the design and use of an object/relational mapping framework. The insights they provide into the underlying issues of ORM give the reader a deep understanding into the effective application of ORM as an enterprise technology.

Java Persistence with Hibernate thus reaches out to a wide range of developers—from newcomers to object/relational mapping to experienced developers—seeking to learn more about cutting-edge technological innovations in the Java community that have occurred and are continuing to emerge as a result of this work.

Linda DeMichiel Specification Lead Enterprise JavaBeans 3.0 and Java Persistence Sun Microsystems

Preface

The predecessor of this book, Hibernate in Action, started with a quote from Anthony Berglas: "Just because it is possible to push twigs along the ground with one's nose does not necessarily mean that that is the best way to collect firewood." Since then, the Hibernate project and the strategies and concepts software developers rely on to manage information have evolved. However, the fundamental issues are still the same—every company we work with every day still uses SQL databases, and Java is entrenched in the industry as the first choice for enterprise application development.

The tabular representation of data in a relational system is still fundamentally different than the networks of objects used in object-oriented Java applications. We still see the object/relational impedance mismatch, and we frequently see that the importance and cost of this mismatch is underestimated.

On the other hand, we now have a range of tools and solutions available to deal with this problem. We're done collecting firewood, and the pocket lighter has been replaced with a flame thrower.

Hibernate is now available in its third major release; Hibernate 3.2 is the version we describe in this book. Compared to older Hibernate versions, this new major release has twice as many features—and this book is almost double the size of Hibernate in Action. Most of these features are ones that you, the developers working with Hibernate every day, have asked for. We've sometimes said that Hibernate is a 90 percent solution for all the problems a Java application developer has to deal with when creating a database application. With the latest Hibernate version, this number is more likely 99 percent.

As Hibernate matured and its user base and community kept growing, the Java standards for data management and database application development were found lacking by many developers. We even told you not to use EJB 2.x entity beans in Hibernate in Action.

Enter EJB 3.0 and the new Java Persistence standard. This new industry standard is a major step forward for the Java developer community. It defines a lightweight and simplified programming model and powerful object/relational persistence. Many of the key concepts of the new standard were modeled after Hibernate and other successful object/relational persistence solutions. The latest Hibernate version implements the Java Persistence standard.

So, in addition to the new all-in-one Hibernate for every purpose, you can now use Hibernate like any Java Persistence provider, with or without other EJB 3.0 components and Java EE 5.0 services. This deep integration of Hibernate with such a rich programming model enables you to design and implement application functionality that was difficult to create by hand before.

We wrote this book to give you a complete and accurate guide to both Hibernate and Java Persistence (and also all relevant EJB 3.0 concepts). We hope that you'll enjoy learning Hibernate and that you'll keep this reference bible on your desk for your daily work.


Personal tools