Java Reference
In-Depth Information
applications that use Hibernate. The first of these is as simple as we could make it, so it is an
excellent introduction to the following necessary steps:
Identify the POJOs that have a database representation.
Identify which properties of those POJOs need to be persisted.
Create Hibernate XML mapping files for each of the POJOs that map properties to
columns in a table (covered in more detail in Chapter 7).
Create the database schema using the schema export tool, use an existing database, or
create your own database schema.
Add the Hibernate Java libraries to your application's classpath (covered in this chapter).
Create a Hibernate XML configuration file that points to your database and your XML
mapping files (covered in this chapter).
In your Java application, create a Hibernate Configuration object that references your
XML configuration file (covered in this chapter).
Also in your Java application, build a Hibernate SessionFactory object from the
Configuration object (covered in this chapter).
Finally, retrieve Hibernate Session objects from the SessionFactory , and write your data
access logic for your application (create, retrieve, update, and delete).
Don't worry if you don't understand every term or concept in the preceding list. After
reading this chapter, and then going through the example in the next chapter, you will know
what these terms mean and how they fit together.
Understanding Where Hibernate Fits in Your
Java Application
You can call Hibernate from your Java application directly, or you can access Hibernate
through another framework. You can call Hibernate from a Swing application, a servlet, a
portlet, a JSP page, or any other Java application that has access to a database. Typically, you
would use Hibernate to either create a data access layer for an application or replace an
existing data access layer.
Hibernate supports Java Management Extensions ( JMX), J2EE Connector Architecture
( JCA), and Java Naming and Directory Interface ( JNDI) Java language standards. Using JMX,
you can configure Hibernate while it is running. Hibernate may be deployed as a JCA
connector, and you can use JNDI to obtain a Hibernate session factory in your application.
In addition, Hibernate uses standard Java Database Connectivity ( JDBC) database drivers to
access the relational database. Hibernate does not replace JDBC as a database connectivity
layer—Hibernate sits on a level above JDBC.
In addition to the standard Java APIs, many Java web and application frameworks now
integrate with Hibernate. Hibernate's simple, clean API makes it easy for these frameworks to
support Hibernate in one way or another. The Spring framework provides excellent Hibernate
integration, including generic support for persistence objects, a generic set of persistence
Search WWH ::




Custom Search