flutheronioneyedΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 4 χρόνια και 7 μήνες)

93 εμφανίσεις

“This is to be certified that material is unpublished and original”
Author1: Rakhi Tandon
M.Tech(CS) 1
year, AIET, Lucknow(U.P.)
Email id: rakhikajal@gmail.com
Contact No.- 9838453834
Author 2: Roli Singh
M.Tech(CS) 1
year, IET, Alwar(Rajasthan)
Email id: roli63bit@rediffmail.com
Contact No.- 9044470954
“This is to be certified that material is unpublished and original”
Author1: Rakhi Tandon
M.Tech(CS) 1
year, AIET, Lucknow(U.P.)
Email id: rakhikajal@gmail.com
Contact No.- 9838453834
Author 2: Roli Singh
M.Tech(CS) 1
year, IET, Alwar(Rajasthan)
Author1: Rakhi Tandon
M.Tech(CS) 2
year, AIET, Lucknow(U.P.)
Email id: rakhikajal@rediffmail.com
Contact No.- 9838453834 , 7398223614
Author2: Rishab Dixit
M.Tech(CS) 1
year, SRMCEM, Lucknow(U.P.)
Email id: dixit.rishab@gmail.com
Contact No.- 9936795014 , 8115000032
Storing and retrieving information for most applications usually involves some form of interaction with a
relational database. This has presented a fundamental problem for developers for quite some time since the
design of relational data and object-oriented instances share very different relationship structures within their
respective environments. Relational databases are structured in a tabular configuration and object-oriented
instances are typically structured in a hierarchical manner. This “impedance mismatch” has led to the
development of several different object-persistence technologies attempting to bridge the gap between the
relational world and the object-oriented world. The Hibernate persistence framework provides yet another
means for bridging this gap
Hibernate is a Java framework that provides object/relational mapping mechanisms to define how Java
objects are stored, updated, deleted, and retrieved. In addition, Hibernate offers query and retrieval services
that can optimize development efforts within SQL and JDBC environments. Ultimately, Hibernate reduces
the effort needed to convert between relational database result-sets and graphs of Java objects.
One of its unique features is that Hibernate does not require developers to implement proprietary interfaces
or extend proprietary base classes in order for classes to be made persistent. Instead, Hibernate relies on Java
reflection and runtime augmentation of classes using a powerful, high-performance, code-generation library
for Java called CGLIB. CGLIB is used to extend Java classes and implement Java interfaces at runtime.
Hibernate framework tackles the Java-object-to-database problem as elegantly as any framework currently
available. Hibernate works by persisting and restoring plain old Java Objects (POJOs) using a very
transparent and low-profile programming model.
Object States
Hibernate defines three states for object instances: persistent, detached, and transient. Persistent objects are
ones that are currently associated with a Hibernate session; as soon as the session is closed (or the object is
evicted), the objects become detached. Hibernate ensures that Java objects in a persistent state for an active
session match the corresponding record(s) in the database. Transient objects are ones that are not (and most
likely, never were) associated with Hibernate session and also do not have an object identity.
Data Types
Hibernate supports a large number of Java, SQL, and Hibernate typesmore than you will probably need for a
typical application. Also, you can have Hibernate automatically convert from one type to another by using a
different type for a given property in a entity/class mapping file.
The following is a partial list of types supported: integer, long, short, float, double, character, byte, boolean,
yes_no, true_false, string, date, time, timestamp, calendar, calendar_date, big_decimal, big_integer, locale,
timezone, currency, class, binary, text, serializable, clob, and blob.
The Hibernate Configuration File:
You can configure the Hibernate environment in a couple of ways. One standard way that proves very
flexible and convenient is to store the configuration in a file named hibernate.cfg.xml. You place the
configuration file at the root of a Web application’s context classpath (e.g. WEB-INF/classes).
You then access the file and read it using the net.sf.hibernate.cfg.Configuration class at runtime.
The hibernate.cfg.xml file defines information about the database connection, the transaction factory class,
resource mappings, etc
The following Figure1 and Figure 2 describes the high level architecture of hibernate i.e. they show how
hibernate uses the database and configuration data to provide persistence services (and persistent objects) to
an application. To use Hibernate, it requires creating Java classes that represent the table in the database and
then map the instance variable in the class with the columns in the database. Then, Hibernate can be used to
perform operations on the database like select, insert, update and delete the records in the table.
Hibernate automatically creates the query to perform these operations. The Figure1 describes the high level
architecture of hibernate.
Figure 1. Basic Hibernate Architecture
Hibernate architecture has following three main components.
Connection management:
Hibernate Connection management service grant efficient management of the database connections.
Database connection is the priciest part of database as it requires a lot of resources of open/close the database
Transaction management:
Transaction management service provides the capability to the user to execute more than one database
statements at a time.
Object relational mapping:
Object relational mapping is a technique of mapping the data representation from an object model to a
relational data model. This part of the hibernate is used to select, insert, update, view and delete the records
form the underlying table. When we pass an object to a Session.save() method, hibernate reads the state of
the variables of that object and executes the necessary query. Hibernate is extremely good tool as far as
object relational mapping is concern, but in terms of connection management and transaction management, it
lacks in performance and capabilities. So usually hibernate is being used with other connection management
and transaction management tools. For example apache DBCP is used for connection pooling with
the hibernate. Hibernate provides a lot of flexibility in usage. It is called "Lite" architecture when we only
use object relational mapping component. While in "Full Cream" architecture all the three component Object
Relational mapping, Connection Management and Transaction Management are used. Hibernate architecture
can be shown in detail in the figure 2.
Figure 2. A detailed Hibernate Architecture
Hibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but instead of
operating on tables and columns, HQL works with persistent objects and their properties. HQL queries are
translated by Hibernate into conventional SQL queries which in turns perform action on database.
Although you can use SQL statements directly with Hibernate using Native SQL but I would recommend to
use HQL whenever possible to avoid database portability hassles, and to take advantage of Hibernate's SQL
generation and caching strategies.
Keywords like SELECT , FROM and WHERE etc. are not case sensitive but properties like table and
column names are case sensitive in HQL
In this section we will discuss Hibernate advantages and disadvantages, and see why we should or shouldn't
use Hibernate. Hibernate is an ORM tool that automatically

maps your domain object to the relational
database. It helps to developers to quickly write database access program and become productive. But we
will see the advantages and disadvantages of Hibernate ORM tool.
Java developers of all over the world is mostly using Hibernate or JPA (with Hibernate) for developing
enterprise web applications. There are lots of material and tutorials on Hibernate on the web. As a developer
if you are stuck some where in your programming, you can easily find the solution of your problem on the
Advantages of Hibernate
 Hibernate is better then plain JDBC: You can use Hibernate which generates the SQL on the fly
and then automatically executes the necessary SQL statements. This saves a lot of

development and
debugging time of the developer. Writing JDBC statement, setting the parameters, executing query
and processing the result by hand is lot of work. Hibernate will save all tedious efforts.
 Mapping of Domain object to relational database:

Hibernate maps your domain object with the
relational database. Now you can concentrate on your business logic rather than managing the data in

Layered architecture:

Hibernate is layers architecture and you can use the components as per your
application need.

JPA Provider:

Hibernate can work as JPA provider in


based applications.

 Standard ORM: Hibernate is standard ORM solutions and it also supports JPA.
 Database Independent: Hibernate is database independent and you can use any database of your

 Caching Framework: There are many caching framework that works with Hibernate. You can use
any one in your application to improve the performance of your application.

Disadvantages of Hibernate
 Lots of API to learn: A lot of effort is required to learn Hibernate. So, not very easy to learn
hibernate easily.

Sometimes debugging and performance tuning becomes difficult.

Slower than JDBC:
Hibernate is slower than pure JDBC as it is generating lots of SQL
statements in runtime.

 Not suitable for Batch processing:

It advisable to use pure JDBC for batch processing.
This paper has illustrated an introduction to what hibernate can do. The analyses how hibernate delivers a
high performance, open source persistence framework comparable to many of its open source and
commercial counterparts. Developers utilizing Hibernate can greatly reduce the amount of time and effort
needed to code, test, and deploy applications. Hibernate is a powerful, highperformance, feature-rich and
very popular ORM solution for Java along with mapping objects to a database. As discussed above hibernate
also provides advanced data query and retrieval services through HQL, efficient caching, and other
optimization techniques with useful built-in utilities for coding and schema generation. This automats the
generation of a persistent layer to a large extent and hence, helps in relieving the developer up to 95% of
common persistence related coding.
[1] Beginning Hibernate: from novice to professional, jefflinwood .
[2] http://www.devarticles.com.
[3] http://www.mindfiresolutions.com.
[4] Professional Hibernate (programmer to
programmer),Ericpugh .
[5] http://www.apress.com.
[6] Java Persistence with Hibernate Second Edition of Hibernate in Action Christian Bauer and Gavin King.
[7] http://www.yangdaoqi.info.
[8] Hibernate in Action, Christian Bauer and Gavin King.
[9] Spring Persistence with Hibernate, AhmadSeddighi.
[10] Web development with java:using Hibernate,jsps and servlets,TimDowney.
[11] JBoss as 5 developments, Francescomarchon