[go: up one dir, main page]

0% found this document useful (0 votes)
47 views8 pages

Hibernate Technology For An Efficient Business Application Extension

The document discusses Hibernate technology as an object-relational mapping tool for Java applications. It provides an overview of Hibernate's architecture and how it maps objects to database tables, as well as its query language capabilities. Hibernate allows developers to work with objects instead of direct SQL queries to access and manipulate data in the database.

Uploaded by

Drajan Lama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views8 pages

Hibernate Technology For An Efficient Business Application Extension

The document discusses Hibernate technology as an object-relational mapping tool for Java applications. It provides an overview of Hibernate's architecture and how it maps objects to database tables, as well as its query language capabilities. Hibernate allows developers to work with objects instead of direct SQL queries to access and manipulate data in the database.

Uploaded by

Drajan Lama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Volume 2, No.

6, June 2011
Journal of Global Research in Computer Science
REVIEW ARICLE
Available Online at www.jgrcs.info

HIBERNATE TECHNOLOGY FOR AN EFFICIENT BUSINESS APPLICATION


EXTENSION
B.Vasavi*1, Y.V.Sreevani2, G.Sindhu Priya3
*1
Associate Professor, Department of Computer Science and Engineering
Hyderabad Institute of Technology and Management [HITAM], Hyderabad, A.P, India.
vasavi.bande@yahoo.co.in
2
Associate Professor, Department of Computer Science and Engineering
Hyderabad Institute of Technology and Management [HITAM], Hyderabad, A.P, India
s_vanikumar@yahoo.co.in
3
Student, B.Tech Final Year, Department of Computer Science and Engineering
Hyderabad Institute of Technology and Management [HITAM], Hyderabad, A.P, India
sindhupriya78@gmail.com

Abstract :This paper discusses hibernate technology as a novel and efficient means to access huge databases and also focuses on how to
implement persistent features in object-oriented system through it . It discusses currently available hibernate mapping framework in detail.
Hibernate provides support for collections, object relations, as well as complex and composite types. In addition to persisting objects,
hibernate also provides a rich query language to retrieve objects from the database, along with an efficient caching layer and Java
Management Extensions (JMX) support. Hibernate is a powerful, high-performance, feature-rich and very popular ORM solution for Java.
Hibernate facilitates development of persistent objects based on the common Java object model to mirror the underlying database structure.
This approach progresses the business performance to some extent, advances development efficiency exceedingly and obtains preferable
economical efficiency and practicability. In addition to, it compares and analyzes the database access efficiency resulted from two
mechanisms based on Hibernate and JDBC. This paper offers insight into hibernate technology its implementation and usage.

Keywords: Hibernate, HQL, ORM,, Database, SQL.

support for collections and object relations, as well as


INTRODUCTION composite types. It also provides a rich query language to
A major portion of the development of an enterprise retrieve objects from the database, a competent caching layer
application involves the creation and maintenance of the and has Java Management Extensions (JMX) support.
persistence layer used to accumulate and retrieve objects Hibernate is released under the lesser GNU Public License,
from the database of choice [1]. Many organizations resort which is sufficient for use in commercial as well as open
to create homegrown, often buggy, persistence layers. If source applications. It supports numerous databases,
changes are made to the underlying database schema, it can including Oracle and DB2, also popular open source
be expensive to disseminate those changes to the rest of the databases such as PostgreSQL and MySQL.
application. Hibernate steps in to fill this gap, providing an
easy-to-use and powerful object relational persistence Working of Hibernate
framework for Java applications. Hibernate is an object-
relational mapping (ORM) library for the Java language, Rather than utilizing bytecode processing or code
providing a framework for mapping an object-oriented generation, hibernate uses runtime reflection to determine
domain model to a traditional relational database. Hibernate the persistent properties of a class. The objects to be
solves Object-Relational impedance mismatch problems by persisted are defined in a mapping document, which serves
replacing direct persistence-related database accesses with to describe the persistent fields and associations, as well as
high-level object handling functions. ORM is a piece of any subclasses or proxies of the persistent object. The
software product for the representation and translation of mapping documents are compiled at application startup
data between the database and the object-oriented time and supply the framework with necessary information
programming language. Hibernate is one such ORM solution for a class [2]. In addition to it, they are used in support
and it is an open-source project. The Hibernate 2.1 operations, such as generating the database schema or
framework has won a award in 2005. Hibernate provides creating stub and Java source files. A Session Factory

© JGRCS 2010, All Rights Reserved 118


B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

is created from the compiled collection of mapping Object relational mapping:


documents[6]. The Session Factory provides the mechanism
for managing persistent classes and the Session interface. Object relational mapping is a technique of mapping the data
The Session class provides the interface between the representation from an object model to a relational data
persistent data store and the application. The Session model. This part of the hibernate is used to select, insert,
interface wraps a JDBC connection, which can be user- update, view and delete the records form the underlying
managed or controlled by hibernate, and is only intended to table. When we pass an object to a Session.save() method,
be used by a single application thread, then closed and hibernate reads the state of the variables of that object and
discarded. executes the necessary query. Hibernate is extremely good
tool as far as object relational mapping is concern, but in
Hibernate Architecture terms of connection management and transaction
The following Figure1and Figure 2 describes the high level management, it lacks in performance and capabilities. So
architecture of hibernate i.e. they show how hibernate uses usually hibernate is being used with other connection
the database and configuration data to provide persistence management and transaction management tools. For
services (and persistent objects) to an application. To use example apache DBCP is used for connection pooling with
Hibernate, it requires creating Java classes that represent the the hibernate. Hibernate provides a lot of flexibility in usage.
table in the database and then map the instance variable in It is called "Lite" architecture when we only use object
the class with the columns in the database. Then, Hibernate relational mapping component. While in "Full Cream"
can be used to perform operations on the database like architecture all the three component Object Relational
select, insert, update and delete the records in the table. mapping, Connection Management and Transaction
Hibernate automatically creates the query to perform these Management are used. Hibernate architecture can be shown
operations. The Figure1describes the high level architecture in detail in the figure 2.
of hibernate.

Figure 2. A detailed Hibernate Architecture

Figure 1. Basic Hibernate Architecture


Hibernate Query Language or HQL for short is extremely
Hibernate architecture has following three main powerful query language. HQL is much like SQL and are
components. case-insensitive, except for the names of the Java Classes
and properties. Hibernate Query Language or HQL for short
Connection management: is extremely powerful query language. HQL is much like
SQL and are case-insensitive, except for the names of the
Hibernate Connection management service grant efficient Java Classes and properties. Hibernate Query Language is
management of the database connections. Database used to execute queries against database. Hibernate
connection is the priciest part of database as it automatically generates the sql query and execute it against
requires a lot of resources of open/close the database underlying database if HQL is used in the application [4].
connection. HQL is based on the relational object models and makes the
SQL object oriented. Hibernate Query Language uses
Transaction management: Classes and properties instead of tables and columns.
Hibernate Query Language is extremely powerful and it
Transaction management service provides the capability to supports Polymorphism, Associations and is less verbose
the user to execute more than one database statements at a than SQL. There are other options that can be used while
time. using hibernate [3]. These are Query By Criteria (QBC)

© JGRCS 2010, All Rights Reserved 119


B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

and Query BY Example (QBE) -using Criteria API and the class.
Native SQL queries. b) Column: The column used to store the primary key
Full support for relational operations- HQL permits value.
representing SQL queries in the form of objects. Hibernate c) Type: The Java data type is used.
Query Language uses Classes and properties instead of d) unsaved-value: This is the value used to determine if a
tables and columns. class has been made persistent. If the value of the id
Return result as Object- The HQL queries return the query attribute is null, then it means that this object has not
result(s) in the form of object(s), which is easy to use. This been persisted.
eliminates the need of creating the object and populates the 4. <generator> element: The <generator> method is used
data from result set. to generate the primary key for the new record. Here is some
Polymorphic Queries- HQL fully supports polymorphic of the frequently used generators.
queries. Polymorphic queries provide query results along a) Increment - This is used to generate primary keys of
with all the child objects if any. type long, short or int that are unique only. It should not
Easy to Learn- Hibernate Queries are easy to learn and it be used in the clustered deployment environment.
can be easily implemented in the applications. b) Sequence - Hibernate can also use the sequences to
Support for Advance features- HQL contains many generate the primary key. It can be used with DB2,
advanced features such as pagination, fetch and join with postgreSQL , Oracle, SAPDB databases.
dynamic profiling, Inner/outer/full joins and Cartesian c) Assigned - Assigned method is used when application
products. It also supports Projection, Aggregation (max, code generates the primary key.
avg) and grouping, Ordering, Sub queries and SQL function 5. <property> element: The property elements define
calls. standard Java attributes and their mapping into database
Database independent- Queries written in HQL are schema. The property element supports the column child
database independent. element to specify additional properties, such as the index
name on a column or a specific column type.
UNDERSTANDING AND IMPLEMENTATION OF
HIBERNATE MAPPING Configuring Hibernate
<?xml version="1.0"?> Hibernate can be configured by creating a property file
<!DOCTYPE hibernate-mapping SYSTEM named hibernate properties in the src directory and adding
“Hibernate_Mapping.dtd”> its path to the application's classpath. This file consists of the
<hibernate-mapping> properties used by Hibernate to connect to database[11],
<class name=”sample” table=”COMMUNICATE”> generate schema, and obtain other database-specific
<idname=”id”type=”long”column=”ID”><generator information. To reflect changes in the underlying database
class=”assigned”/> </id> into the whole application, only values of the properties in
<property name=”firstName”> <column this file need to be modified. Model 1 shows a simple
name=”FIRSTNAME”/> </property> example. Most of these properties are self-explanatory. To
<property name=”lastName”> <column set up MySQL Database in the configuration file i.e.
name=”LASTNAME”/> </property> hibernate.cfg.xml.Considering database running on the
</class> localhost. So, create the database ("hibernate tutorial") on
</hibernate-mapping> the MySQL server running on local host.
Hibernate mapping documents are simple xml documents
[10]. Model 1: A simple example of hibernate properties file:
Here are some important elements of the mapping file: hibernate.connection.driver_class =
1. <hibernate-mapping> element: The first or root element COM.ibm.db2.jdbc.app.DB2Driver
of hibernate mapping document is <hibernate-mapping> hibernate.connection.url = jdbc: db2: inventory
element between the <hibernate-mapping> tag class hibernate.connection.username = db2admin
element(s) are present [3]. hibernate.connection.password = Taman
2. <class> element: The <class> element maps the class hibernate.dialect = cirrus.hibernate.sql.DB2Dialect
object with corresponding entity in the database. It also tells
what table in the database has to access and what column in Hibernate also can be configured by using a simple XML
that table it should use. Within one <hibernate- mapping> file named hibernate.cfg.xml, which exists inside the src
element, several <class> mappings are possible. directory. This file's structure is very similar to hibernate
3. <id> element: The <id> element is unique identifier to properties and has the same functionality. This shown as
identify and object. In fact <id> element map with the example
primary key of the table in our code <id name="id" in the following model.
type="long" column="ID" > primary key maps to the ID
field of the table COMMUNICATE. The attributes of the id Model 2: Example of a simple hibernate.cfg.xml
element are: <? xml version="1.0"?>
a) Name: The property name used by the persistent <!DOCTYPE hibernate-mapping SYSTEM
“Hibernate_Mapping.dtd”>
© JGRCS 2010, All Rights Reserved 120
B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

<hibernate-mapping> This task becomes simpler after mapping documents are


<calss name=”sample” table=”COMMUNICATE”> created. Stub classes can be created by using Hibernate's built-
<id name=”id” type=”long” column=”ID”><generator in utility CodeGenerator by executing a simple command.
class=”assigned”/> </id> Command's syntax is given below:
<property name=”firstName”> <column java -cp classpath
name=”FIRSTNAME”/> </property> net.sf.hibernate.tool.hbm2java.CodeGenerator: options
<property name=”lastName”> <column mapping files.
name=”LASTNAME”/> </property> Provide appropriate values for the class path, options, and
</class> mapping files parameters. Model 4 shows the stub file
</hibernate-mapping> generated using the mapping document given in model 3.

Building an Application with Hibernate Model 4: Stub Classes


We can build a application by adhering to the following package com.myPackage.myApplication;
steps. public class Event {
• Creating mapping documents. private String title;
• Generating stub Java classes for persistent objects. private Date date;
• Generating database schema. private Long id;
• Preparing code to initialize and run Hibernate in an Event(){ }
appropriate place . public Long getId() {
These steps are explained in the following sections. return id;
}
Creating Mapping Documents private void setId(Long id) {
Mapping documents are XML documents used to define this.id = id;
the persistent objects and contain information about an }
object's persistent fields, associations, subclasses, and public Date getDate() {
proxies, if any [3]. One mapping document is created for return date;
each persistent object and saved in a file with the name }
class_name.hbm.xml, where class_name is the name of the public void setDate(Date date) {
object's class. Model 3 and Model 4 gives an example of this.date = date;
mapping document Event.hbm.xml. The mapping }
documents are compiled at application start-up to provide public String getTitle() {
hibernate with information about the persistent objects' return title;
corresponding classes, their respective structures, to which }
database table should they be mapped, and how. Hibernate public void setTitle(String title) {
also uses these mapping documents to generate this.title = title;
corresponding database schema and stub Java classes for the }
persistence layer, using inbuilt utilities called SchemaExport }
and CodeGenerator respectively.
Generating Database Schema
Model 3: An example of mapping document Event.hbm.xml Mapping files in hand, it’s time to generate the database
<! DOCTYPE hibernate-mapping PUBLIC schema [7]. Hibernate ships with the SchemaExport utility
"-//Hibernate/Hibernate Mapping DTD 2.0//EN" that will create the schema necessary for the mapping
"http://hibernate.sourceforge.net/hibernate-mapping- documents. This utility may be run from the command line
2.0.dtd"> or from an build script to connect to the database and
<Hibernate-mapping> create the schema, or to export the schema to a file. To
<class name="com.myPackage.myApplication.Event" generate database schema using Hibernate's SchemaExport,
table="EVENTS"> execute the following command after substituting
<id name="id" column="uid" type="long"> appropriate values for parameters:
<generator class="increment"/> java -cp classpath
</id> net.sf.hibernate.tool.hbm2ddl.SchemaExport options
<property name="date" column="event_date" mapping_files.
type="timestamp"/> Provide appropriate values for the classpath, options, and
<property name="title" column="event_title" mapping_files parameters. Figure 3 shows the schema
type="string"/> generated using the mapping document given in model 3.
</class>
</hibernate-mapping>

Generating Stub Classes

© JGRCS 2010, All Rights Reserved 121


B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

CREATING THE SESSION FACTORY


The SessionFactory stores the compiled mapping documents
specified when the factory is created. Configuring the
SessionFactory is fairly straightforward as shown in figure 4.
All of the mappings are added to an instance of
net.sf.hibernate.cfg.Configuration, which is then used to
create the SessionFactory instance.
Figure 3: Graphical representation of schema as per Model 3 Configuration cfg = new Configuration()
addClass(example.Player.class)
Initializing and Running Hibernate addClass(example.Team.class);
To initialize and run hibernate, the following steps are to be SessionFactory factory = cfg.buildSessionFactory();
taken [8]:
• Inside an appropriate class, instantiate and populate the
desired object to be persisted.
• Obtain the net.sf.hibernate.SessionFactory object using
the net.sf.hibernate.cfg.Configuration object at the start of
the application.
• Open net.sf.hibernate.Session by calling the
openSession() method on the SessionFactory object.
• Save the desired object and close the Session.
Model 5 shows how to implement the steps described above
using a simple class. Now, the application is complete and,
when executed, saves the desired objects to the underlying
database and makes them persistent.

Model 5: A class for initializing Hibernate and making


objects persistent.
package com.myPackage.myApplication;
import net.sf.hibernate.SessionFactory;
Figure 4: Session Factory Mapping
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Transaction; The Configuration class is only needed for the creation of
import net.sf.hibernate.cfg.Configuration; the SessionFactory and can be discarded after the factory is
public class EventManager { built. Instances of Session are obtained by calling
public static void main(String[] args) { SessionFactory.openSession(). The logical lifecycle of a
// Instantiate and populate object to be persisted Session instance is the span of a database transaction. The
Event ev = new Event(); SessionFactory can also be configured using an XML
ev.setDate("22/6/2011") mapping file, placed in the root of
ev.setTitle("Hibernate startup "); your classpath [8]. The evident advantage to this approach is
try { that your configuration isn’t hardcoded in the application.
//Start Hibernate
Configuration cfg = new INTERCEPTORS IN HIBERNATE
Configuration().addClass(Event.class); Hibernate provides an ORM solution for persisting and
SessionFactory sf = cfg.buildSessionFactory(); querying data in the database. A Hibernate application can
//Open Session be structured in a way such that certain methods can be
Session sess = sf.openSession(); made and to be invoked when a particular life-cycle event
} catch (HibernateException e) { occurs. Not always the API in a software/product will
e.printStackTrace(); completely satisfy the application needs and requirements.
} Hibernate is no more away from this [9]. Therefore,
//Save Product and close Session Hibernate API is designed in such a way to provide
Transaction t = sess.beginTransaction(); pluggable framework through the concept of Interceptors. In
sess.save(ev); a multi-tiered application, the situation for the inclusion of
t.commit(); Interceptors can happen at any level. It can happen at the
sess.close(); Client level, Server level and even at the persistence level.
Imagine an application is saving employee records in a
} database and now the application mandates to display to the
Database admin about the history of inserts and updates.
}

© JGRCS 2010, All Rights Reserved 122


B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

A simple general overview of the logic looks like the Session session2 =
following, sessionFactory.openSession(myAnotherInterceptor);
- Insert/Update the records in the Database User u1, u2 = null;
- During Insert/Update, maintain the log information in a // assume u1 and u2 objects are associated with session
file as we can see, the maintenance of this logging 'session2'.
information should happen whenever an insert/update goes
to the Database. Such a logger interceptor can be easily From the above code, we can infer that a session-scoped
plugged into the application with minimal code change interceptor can be set by calling the method
because of the flexible design of hibernate. SessionFactory.openSession(Interceptor). In the above code,
we have two different session objects 'session1' and
Types of Interceptors 'session2' being configured with Interceptors MyInterceptor
Based on their scope, Interceptors in hibernate can fall under and MyAnotherInterceptor respectively. So, e1 and e2
two categories. They are, objects will be affected by MyInterceptor, whereas u1 and
• Application-scoped Interceptors u2 objects will be affected by MyAnotherInterceptor.
• Session-scoped Interceptors
IMPLEMENTATION FOR TESTING HIBERNATE
Application-scoped Interceptor APPLICATION
An application can contain one or more database sessions Now we are ready to write a program to insert the data into
represented by the Session interface. If an application is database. We should first understand about the hibernates
configured to use Global Interceptors, then it will affect the Session. Hibernate Session is the main runtime interface
persistent objects in all the sessions. The following code between a Java application and hibernate [7]. First we are
configures a global interceptor. required to get the hibernate Session. SessionFactory allows
SessionFactory sessionFactory = application to create the hibernate Session by reading the
configuration.buildSessionFactory(); configuration from hibernate.cfg.xml file. Then the save
Session session1 = sessionFactory.openSession(); method on session object is used to save the contact
Employee e1, e2 = null; information to the database.
// Assume e1 and e2 objects are associated with session1. session.save(communicate)
Session session2 = sessionFactory.openSession(); Here is the code of First Example1.java
User u1, u2 = null package roseindia.tutorial.hibernate;
//Assume u1 and u2 objects are associated with session1. import org.hibernate.Session;
import org.hibernate.SessionFactory;
A global-scoped interceptor can be set to an application by import org.hibernate.cfg.Configuration;
calling the Configuration.setInterceptor(Interceptor) method. public class FirstExample {
In the above code, we have two different session objects public static void main(String[] args) {
'session1' and 'session2'. Let us assume that e1 and e2 Session session = null;
Employee objects are associated with session 'session1' and try{
u1 and u2 are the user objects associated with session // This step will read hibernate.cfg.xml and prepare hibernate
'session2'. The applied application-scoped interceptor would for use
have affected all the objects (e1, e2, u1 and u2), even though SessionFactory sessionFactory = new
they are in different sessions. Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Session-scoped Interceptor //Create new instance of Communicate and set
A session-scoped interceptor will affect all the persistent values in it by reading them from form object
objects that are associated with that particular session only. System.out.println("Inserting Record");
The following code shows how to configure a session- Communicate contact = new Communicate();
scoped interceptor. contact.setId(3);
Configuration configuration = new Configuration(); contact.setFirstName("jasmine");
SessionFactory sessionFactory = contact.setLastName("Rao");
configuration.buildSessionFactory(); contact.setEmail("jasmine_74@yahoo.com");
MyInterceptor myInterceptor = new MyInterceptor(); session.save(contact);
Session session1 = System.out.println("Done");
sessionFactory.openSession(myInterceptor);
Employee e1, e2 = null; Retrieving Persistent Classes
// Assume e1 and e2 objects are associated with session If you know the primary key value of the object that you
'session1'. want to retrieve, you can load it with the Session.load()
MyAnotherInterceptor myAnotherInterceptor = new method[6]. This method is overloaded to offer support for
MyAnotherInterceptor (); standard classes and BMP entity beans. To retrieve a
persistent class without knowing its primary key value, you

© JGRCS 2010, All Rights Reserved 123


B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

can use the Session.find() methods. The find () method


allows you to pass an HQL (Hibernate Query Language) Performance Considerations
statement and retrieve matching objects as a java.util.List.
The find () method has three signatures, allowing you to pass Fortunately this functionality doesn’t come at much of a
arguments to JDBC-like “?” parameters as a single performance cost. The hibernate website claims that its
argument, named parameters, or as an Object[]. “overhead is much less than 10% of the JDBC calls,” and
our experience in deploying applications using hibernate
Deleting Persistent Classes supports this. Hibernate can make multiple optimizations
Making a persistent object transient is accomplished with the when interacting with the database, including caching
Session.delete () method. This method supports passing objects, efficient outer join fetching and executing SQL
either a specific object to delete or a query string to delete statements only when needed [9]. It is difficult to achieve
multiple objects from the database. this level of sophistication with hand-coded JDBC.
// method 1 – deleting the Player.
session.delete(player); ADVANTAGES AND DISADVANTAGES OF
// Example 2 – deleting all of the Players with a salary HIBERNATE
greater than 4 million Hibernate is better than plain JDBC: You can use hibernate
session.delete(“from player in class example.Player where which generates the SQL very easily and then automatically
player.annualSalary > 4000000”); executes the necessary SQL statements [10]. This saves a lot
It’s important to note that while the object may be deleted of development and debugging time of the developer.
from the database, your application may still hold a Writing JDBC statement, setting the parameters, executing
reference to the object. Deleting an object with collections of query and processing the result by hand is plenty of work.
objects, such as the Team’s set of Players, can cascade to Hibernate will save all tiresome efforts.
child objects by specifying cascade=”delete” for the set
element in the mapping document. Mapping of Domain object to relational database:
Hibernate maps your domain object with the relational
Collections database [3]. Now you can concentrate on your business
logic rather than managing the data in the database.
Hibernate can manage the persistence of object collections Light weight database-independent ORM solution
[5], whether they are Sets, Maps, Lists, arrays of objects or Layered architecture: Hibernate is layers architecture and
primitive values. It also allows a different form of collection you can use the components as per your application need.
called a “bag”. A bag can be mapped to a Collection or List,
and contains an unordered, unindexed collection of entities JPA Provider: Hibernate can work as JPA provider in JPA
[6]. Bags can contain the same element many times. based applications.
Additional semantics supported by implementing classes,
such as Linked List, are not maintained when persisted. Standard ORM: Hibernate is standard ORM solutions and it
Another note is that the property of a collection must be the also supports JPA.
interface type (List, Map, Set). This is because, in order to
support lazy collections, hibernate uses its own Database Independent: Hibernate is database independent
implementations of the List, Map or Set interfaces. When and you can use any database of your choice.
accessing a lazily initialized collection, it’s important to
remember that a Session must be open, or an exception will Caching Framework: There are many caching framework
be thrown as given below. that works with Hibernate. You can use any one in your
Session session = factory.openSession(); application to improve the performance of your application.
Team team = (Team) session.find(“from team in class
example.Team where Disadvantages of Hibernate
team.city = ?”, cityName, Hibernate.STRING).get(0);
Set players = team.getPlayers(); Lots of API to learn: A lot of effort is required to learn
session.close(); Hibernate. Not so easy to learn hibernate easily
Player p = (Player) players.get(0); // exception will be Debugging: Sometimes debugging and performance tuning
thrown here becomes difficult.
The exception is thrown because the Session needed to Slower than JDBC: Hibernate is slower than pure JDBC as
populate players was closed prematurely. Because of the it is generating lots of SQL statements in runtime
potential for this bug, hibernate defaults to non lazy Not suitable for Batch processing: It sensible to use pure
collections. However, lazy collections should be used for JDBC for batch processing.
performance reasons.
CONCLUSION

This paper has illustrated an introduction to what hibernate


can do. The analyses how hibernate delivers a high
© JGRCS 2010, All Rights Reserved 124
B.Vasavi et al, Journal of Global Research in Computer Science, Volume 2 Issue (6), June 2011,

performance, open source persistence framework Technology and Management, Hyderabad [HITAM], A.P,
comparable to many of its open source and commercial India. She has presented many papers to her credit at National
counterparts. Developers utilizing Hibernate can greatly and National conferences. She has presided over as judge to
reduce the amount of time and effort needed to code, test, many Paper Presentations and Technical Quizzes. She has
and deploy applications. Hibernate is a powerful, high- authored 4 research papers and are published in reputed and
performance, feature-rich and very popular ORM solution indexed International Computer Science Journals. She has
for Java along with mapping objects to a database. As guided 20 Students of Master degree in Computer Science and
discussed above hibernate also provides advanced data query Engineering in their major projects. She is bestowed with the
and retrieval services through HQL, efficient caching, and Editorial Member on five International Journals Boards and is
other optimization techniques with useful built-in utilities for nominated as Reviewer to three International Journals. Her
coding and schema generation. This automats the generation area of research includes TIBCO; Cloud computing, Network
of a persistent layer to a large extent and hence, helps in Security, Image Processing, Data Mining, Web Technologies
relieving the developer up to 95% of common persistence and Emerging Technologies. She can be reached at:
related coding. vasavi.bande@yahoo.co.in

REFERENCES:
[1] Beginning Hibernate: from novice to professional,
jefflinwood .
[2] http://www.devarticles.com.
[3] http://www.mindfiresolutions.com. 2. Y.V.Sreevani Graduated in AM.I.E.T.E. from
I.E.T.E, New Delhi, India, in 1997 and M.Tech in Computer
[4] Professional Hibernate (programmer to
science from Osmania University, Hyderabad, A.P., India in
programmer),Ericpugh . 2003. She has published 3 International papers. She is presently
[5] http://www.apress.com. working as Associate Professor in Department of Computer
[6] Java Persistence with Hibernate Second Edition of Science and Engineering, Hyderabad Institute of Technology and
Hibernate in Action Christian Bauer and Gavin King. Management, Hyderabad [HITAM], A.P, India. Her area of
[7] http://www.yangdaoqi.info. research includes Network Security, Data Mining, Web Mining
[8] Hibernate in Action, Christian Bauer and Gavin King. Technologies and Emerging Technologies. She can be reached
[9] Spring Persistence with Hibernate, AhmadSeddighi. at: s_vanikumar@yahoo.co.in
[10] Web development with java:using Hibernate,jsps and
servlets,TimDowney.
[11] JBoss as 5 developments, Francescomarchoni.

Authors:
3. G. Sindhu Priya is pursuing B.Tech in
Computer Science and Engineering, Hyderabad Institute of
Technology and Management, Hyderabad [HITAM], A.P,
India. She has participated in number of paper presentations
and technical workshops. She is a noted and active member of
1. Vasavi Bande is M.Tech in Computer Science from the Sahaya Society, a organization to educate the less
Jawaharlal Nehru Technological University, A.P., India. She privileged school students i.e. www.sahayasociety.org. She
has vast experience in Computer Science and Engineering area has organized number of events which include Cultural,
pertaining to academics and industry related real time projects. Symposiums and blood donation camps. She can be reached:
She is presently working as Associate Professor in Department sindhupriya78@gmail.com
of Computer Science and Engineering, Hyderabad Institute of

© JGRCS 2010, All Rights Reserved 125

You might also like