19 integrating hibernate into spring, Why integrate hibernate into spring, Example of integrating hibernate into spring – HP Integrity NonStop J-Series User Manual

Page 367: Chapter 19: integrating hibernate into spring, Prerequisites

Advertising
background image

19 Integrating Hibernate into Spring

This chapter describes how a Spring application can use Hibernate for its database operation.
This is demonstrated by modifying the EmpInfo application (developed in the

“Getting Started with

Spring” (page 75)

chapter) using the Eclipse Galileo IDE.

The following topics are discussed in this section:

“Why Integrate Hibernate into Spring” (page 367)

“Example of Integrating Hibernate into Spring” (page 367)

Why Integrate Hibernate into Spring

Hibernate is a powerful ORM tool that enables an application to access data from any database
in a platform-independent manner. Therefore, the need for Spring to depend on low-level JDBC
details, such as managing connections, dealing with statements and result sets, is greatly reduced.
As a result, all necessary details for accessing a particular data source can be configured in XML
files.

However, a disadvantage of using Hibernate is that the client application that accesses the database
using Hibernate framework will depend on Hibernate APIs, such as Configuration, SessionFactory
, and Session. These APIs will continue to get scattered across the code throughout the application.
Moreover, the application code must be manually maintained to manage the business objects.

In Spring, the business objects can be highly configurable using the Inversion of Control (IOC)
Container. Therefore, the state of an object can be externalized from the application code, thereby
enabling the use of Hibernate objects as Spring Beans. Also, the Data Access Object (DAO) support
in Spring facilitates data access technologies such as JDBC, Hibernate, or Java Data Objects (JDO)
in a consistent way.

The JDBC support in Spring for Object Relational Mapping frameworks provide integration points
to the frameworks and other services such as:

Integrated support for Spring declarative transactions

Transparent exception handling

Thread-safe and lightweight template classes

DAO support classes

Resource management

Integrating Hibernate with Spring allows the application to use both the Spring features and the
Hibernate features of accessing the database.

Example of Integrating Hibernate into Spring

The EmpInfo application (described in the

“Getting Started with Spring” (page 75)

chapter) is a

Spring application that uses JDBC for handling database operations.

This section describes how to use Hibernate for handling database operations of the EmpInfo
application.

Prerequisites

The prerequisites for integrating the EmpInfo application with Hibernate are:

Basic knowledge of the Spring and Hibernate frameworks.

EmpInfo application (explained in the

“Getting Started with Spring” (page 75)

chapter)

developed on the Windows system.

Why Integrate Hibernate into Spring 367

Advertising
This manual is related to the following products: