Table of Contents
Target Audience
This tutorial is designed for Java programmers who need to understand the Hibernate framework and its application.
Prerequisites:
Before proceeding with this tutorial you should have a good understanding of the Java programming language and also good understanding of SQL.
This is 1 of 8 parts of tutorial series
Tutorial Content:
- Introduction to hibernate framework
- Hibernate hello world example in eclipse
- Difference between openSession and getCurrentSession
- Hibernate one to one mapping example
- Hibernate one to many mapping example
- Hibernate many to many mapping example
- Hibernate inheritance:Table per class hierarchy
- Hibernate inheritance:table per subclass
- Hibernate inheritance:Table per concrete class
- Difference between openSession and getCurrentSession
- Difference between get and load
- Spring MVC Hibernate MySQL CRUD example
- Spring Rest hibernate example
What is ORM?
ORM is a programming method to map the objects in java with the relational entities in the database.In this,entities/classes refers to table in database,instance of classes refers to rows and attributes of instances of classes refers to column of table in database.This provides solutions to the problems arise while developing persistence applications using traditional JDBC method. This also reduces the code that needs to be written.
Need for tools like hibernate:
- High-level object-oriented API
- Less Java code to write
- No SQL to write
- Sophisticated caching
- Lazy loading
- Eager loading
- A lot less code to write
- ORM framework generates database-specific SQL for you
What is hibernate?
Architecture of hibernate :
Core classes of hibernate are:
Session Interface:
1 2 3 |
Session session=SessionFactory.openConnection(); |
This is a factory that delivers the session objects to hibernate application.It is a heavy weighted object so generally there will be a single SessionFactory for the whole application and it will be shared among all the application threads.The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime. It also holds cached data that has been read in one unit of work and may be reused in a future unit of work.
1 2 3 4 5 6 |
Configuration configuration=new Configuration(); configuration.configure(); ServiceRegistry sr= new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); SessionFactory sf=configuration.buildSessionFactory(sr); |
SessionFactory object is created with the help of configuration object.
Configuration 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.
it is good…. give some more real examples
Is it possible to create object of Configuration interface?
plz chk above code ..
Configuration configuration=new Configuration();
yes its posible
Configuration cfg = new Configuration();
cfg.configure(“hibernate1.cfg.xml”);
Nice one…
I too had wrote one blog on ORM and hibernate.
You can have a look at http://prasunejohn.blogspot.in/2013/07/an-introdu…
Good Tutorial, Thanks for your contribution…
good
Is Configuration class or interface?
If you say yes, can we create object for java interface.
Plz explain me.
Hello Sir,I am a Sachin and beginer in java.I followed your tutorials properly to learn hibernate and they work well.But when i created HibernateMain.java file.This file shows errors.The Following import can not be resolved.
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
Sir please tell me where i made a mistake.what is the solution for this.
Nice Article
Good Article
Hibernate is open source light weight ORM (Object Relational Mapping) tool
It is a powerful, ultra –high performance object/relational persistence and query service for Java
It simplifies the development of java application to interact with database.
It lets us develop persistent objects following common Java idioms – including association, inheritance, polymorphism, composition and the Java collections framework
It internally uses the JDBC API to interact with the database.
Hibernate Query language is designed as a “minimal” object oriented extension to SQL, provide an elegant bridge between the object and relational worlds.