Magazine
 
Hibernate

How Hibernate Works?

Hibernate is driven by XML configuration files to configure data connectivity and map classes to database tables with which it needs to interact. These XML files contain database connection specifics, connection pooling details, transaction factory settings, as well as references to other XML files that describe tables in the database.

When developer writes code to call API, the called API executes necessary SQL at runtime. Rather than use of byte-code processing or code generation, Hibernate uses runtime reflection to resolve the persistent properties of a class. The persisted objects are defined in a mapping
document, which describes the persistent fields and associations, as well as subclasses or proxies of the persistent object. The mapping documents are compiled at the time of application startup and provide the framework
with necessary information for a class.

At the compile-time of mapping documents, a SessionFactory is also created that provides the mechanism for managing persistent classes, and the Session interface. The Session class provides the interface between the persistent stored data and the
application. The Session interface wraps a JDBC connection, which can be user-managed or controlled by Hibernate. This interface is intended only used by a single threadapplication. That means after completing the
session, application is closed and discarded.

Hibernate Architecture

Unlike other technologies, Hibernate provides persistence as a service, rather than as a framework. It integrates flawlessly with various application architectures.

There are two common (recommended) architectures can be seen including Hibernate as a persistence layer.

The following diagram describes the Web (twotiered) Architecture of Hibernate:

 
Hibernate Architecture

The above diagram shows that Hibernate is using XML mapping to configure data connectivity to database tables, and map classes for providing persistence services (and persistent objects) to the application.

To use Hibernate, it is required to create Java classes that represent the table in the database and then map the instance variable in the class with the columns in the database. Once the mapping is complete, various operations like select, insert, update and delete the records can be performed by the Hibernate on the table of database. Hibernate automatically creates the query to perform these operations. It may also be used to persist JavaBeans used by servlets/JSPs in Model View Controller (MVC) architecture.

Now, the following diagram describes the Enterprise (three-tiered) Architecture of Hibernate:

Dec  2007 | Java Jazz Up | 27
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF