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.
Unlike other technologies, Hibernate provides
persistence as a service, rather than as a
framework. It integrates flawlessly with various
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:
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
2007 | Java Jazz Up | 27
|View All Topics
|All Pages of this Issue