In this tutorial ,I will be discussing about basic features of Hibernate.Hibernate is open source tool. It is used for mapping an object oriented domain to relational database. Hibernate is object relational mapping tool in java. Hibernate implements Java Persistence API for data persistence. It helps your application to achieve persistence.
Hibernate is good for those who is not aware about SQL.Hibernate use objects to develop persistence logic which are independence of database.
Object Relational Mapping(ORM):-It is technique where you map object to data store in database.
Lets discuss architecture:-
This interface is used to configure and bootstrap hibernate.
The instance of the interface is used by the application in order to specify the location of hibernate specific mapping document.
Configuration class written in hibernate.cfg file or hibernate.properties file.
Configuration class present in org.hibernate.cfg package.
Configuration file contains all information such as user name ,password,driver ,connection URL and mapping files.
Configuration cfg=new Configuration(); cfg.configure();
Session factory cache generate sql statement and other mapping metadata that hibernate uses at runtime.
There is typically single session factory for whole application.
The session factory interface present in org.hibernate package.
Session factory interface is immutable and thread safe.
This interface abstract the code from any kind of transaction.
This interface is used for data consistency.
Transaction interface use commit() method to make permanent changes in database.
Transaction tx=session.beginTransaction(); Tx.commit();
It is single threaded short lived object representing a conversation between application and persistent store.
Application obtains session interface from session factory for whole application created during application initialization.
Session interface is not thread safe.
It is used for crud operation.
It holds first level cache of persistent object used when navigating object by identifier.
Query and Criteria interface:-
This interface allows user to perform queries and also control flow of query execution.
Hibernate provide different technique to query database such as Named Query and Criteria API.
It is present in org.hibernate package.
Query query=session.createQuery(); Criteria criteria=session.createCriteria();
First Level Cache:-
It is associated with session object.As we know session object is created on demand from session factory.
It is default cache used by hibernate session object while interacting with database.
It is available to session object only and is not accessible to any other session object in any other part of application.
Second Level Cache:-
It is associated with session factory object.
This need to be explicitly enabled.
Advantages of Hibernate Framework:-
Hibernate framework is open source.
It is lightweight.
Hibernate is database independent,your code will work on all database such as Oracle,MySQL,PostgreSQL etc.
Hibernate is set of objects,you don’t need to learn SQL language,You can treat table as object.
You will get benefit of cache.Hibernate support two level of cache.
Hibernate support query cache and it will provide statistics.
Note:-This page will update every time ,new hibernate tutorial published in blog.