Wednesday, November 11, 2009

What Is Hibernate?









What Is Hibernate?


As stated on the Hibernate Web site, the goal of Hibernate "is to relieve the developer from 95 percent of common data persistence related programming tasks." By combining ordinary Java classes with XML descriptors, Hibernate provides an object-oriented view of a relational database.


As shown in Figure 1.2, most Java applications access a relational database via JDBC (route 1, as indicated in the diagram). By using Hibernate, a developer is freed from writing custom JDBC integration code and can focus on writing the presentation and business logic of the application (route 2). This doesn't have to be an all-or-nothing proposition; you can use an existing JDBC application in conjunction with Hibernate, migrating access as you go along.


Figure 1.2. Weblog & Post Java Objects

[View full size image]



Hibernate allows you to choose a development methodology that fits your needs. If you are starting a new project from scratch, you may wish to start with a mapping file, automatically generating both the schema and the Java classes (Chapter 2). Alternatively, you may wish to start from a relational database schema or directly from Java code (Chapters 3 and 4). Each system has pros and cons, as described in the chapter covering it.


There are several conceptual components to Hibernate that will be described in detail in this book. Java classes and XML files are used by Hibernate to bind Java objects to a particular relational database schema (Chapter 5). Straightforward Java-based operations are then used to create, update, query, and delete records (Chapter 6). More complex relationships, including Java collections, class hierarchies, and database one-to-many, many-to-one, and many-to-many relationships can be managed by Hibernate in a very natural manner (Chapter 7). Rich queries can be expressed in terms of both a simple object-oriented query language and a "Criteria" system (Chapter 8). Hibernate has robust support for complex transactions (Chapter 9).



SO MUCH TO LEARN!


When you first start working with Hibernate, it is easy to feel overwhelmed (especially if you haven't already been exposed to an object/relational framework). If you are just starting out, I strongly recommend that you begin by skimming through this text, paying particular attention to sections that outline concepts new to you. Then download the source for this book from my Web site at http://www.cascadetg.com/hibernate/ and work through the examples one by one.


This text assumes a baseline knowledge of Java application development, traditional relational database concepts, and SQL. Many developers (especially those who are largely self-taught) will discover that some of the basic concepts underlying Hibernate are unfamiliar. If you hit such a wall, check with either a recent Java application development text (JDK 1.4 or later) or a solid book on SQL and relational database theory.


I recommend starting with the mapping filebased example described in Chapter 2. Understanding the mapping file is usually the biggest challenge for developers new to Hibernate. By inspecting the Java source and database schema generated by Hibernate, you can quickly understand how Hibernate functions.










    No comments:

    Post a Comment