Before understanding the hibernation
framework, we need to understand the Object Relational Mapping (ORM).
What
is ORM?
ORM is a programming method to assign
objects in java with the relational entities in the database. In this, entities
/ classes refer to the table in the database, the class instance refers to the rows
and attributes of class instances refers to the table column in the database
This provides solutions to problems that arise during the process of developing
persistence applications using the traditional JDBC method. This also reduces
the code that needs to be saved.
Need for tools like hibernate:
The main advantage of ORM like hibernate is that it shields
developers from messy SQL. Apart from this, ORM provides following benefits:
Improved productivity:
§ High-level
object-oriented API
§ Less
Java code to write
§ No
SQL to write
Improved performance:
§ Sophisticated
caching
§ Lazy
loading
§ Eager
loading
Improved maintainability:
§ A
lot less code to write
Improved portability:
§ ORM
framework generates database-specific SQL for you
What is hibernate?
Hibernate is a relational object mapping (ORM) and a
persistence structure that allows you to assign simple old Java objects to
relational database tables. The main objective of hibernate is to free the
developer from common tasks related to data persistence. the objects in the
java with the tables in the database very efficiently and also you can get the
most out of using your facilities of consultation and data recovery. Mainly
using Hibernate in your projects, you can save incredible time and effort.
Architecture of hibernate :
Following is a detailed view of the Hibernate Application
Architecture with few important core classes.
The Hibernate architecture is placed in layers
to keep it isolated from having to know the underlying APIs. Hibernate is like
a bridge between the Java application and the relational database.
Session
interface:
This is the main interface used by hibernation
applications. Instances of this interface are slight and are not expensive to
create and destroy. Hibernation sessions are not secure threads. It allows you
to create query objects to retrieve persistent objects. It refers to the JDBC
Factory for Transaction connection. It contains a mandatory cache (first level)
of persistent objects, which is used when navigating the object graphic or
searching for objects by identifier.
Session session=SessionFactory.openConnection();
SessionFactory Interface:
This is a factory that delivers session objects
to hibernate the application. It is a heavy object, so there will usually be a
single SessionFactory for the entire application and it is shared among all
sub-processes of the application. SessionFactory caches generate SQL statements
and other metadata mapping that Hibernate uses at runtime. It also stores
cached data that has been read in a unit of work and can be reused in a future
unit of work.
Configuration configuration=new
Configuration();
configuration.configure();
ServiceRegistry sr= new ServiceRegistryBuilder().applySettings(configuration.ge tProperties()).buildServiceRegistry();
SessionFactory sf=configuration.buildSessionFactory(sr);
SessionFactory object is created with the help of configuration
object.
Configuration Interface :
This is used to configure hibernate. It’s also used to bootstrap
hibernate. Mapping documents of hibernate are located using this interface.
Transaction Interface :
This is an optional interface but the
above three interfaces are mandatory in each and every application. This
interface abstracts the code from any kind of transaction implementations such
as JDBC transaction, JTA transaction.
Query and Criteria Interface :
This interface allows the user to perform
queries and also control the flow of the query execution.
To getting expert-level
training for Java Training in your location – java
training in chennai | java
training in bangalore | java
training in pune | java
training in chennai | java
training in bangalore | java
training in tambaram | java
training in omr | java
training in velachery | java
training in annanagar | java
training in chennai | java
training in marathahalli | java
training in btm layout | java
training in jayanagar | java training in chennai | java
training in usa | For getting java online
training | java
online training
No comments:
Post a Comment