Java

HIBERNATE AS ORM TOOL

HIBERNATE AS ORM TOOL

Object Relational Mapping (ORM) method is used for mapping objects into database systems. The instance of classes refers to rows and attributes of a class instance refers to column of table in database.

Hibernate is a persistence framework based on ORM method that allows to relieve form common database oriented problems. The Hibernate architecture is composed of four layers Java application layer, Hibernate framework layer, Backhand api layer and Database layer. These layers are needed to keep it isolated from underlying APIs. The components of Hibernate Architecture are Session Factory, Session, Transaction Factory, Transaction, Configuration interface. The Hibernate acts as a bridge between Java applications and relational database.

Configuration Interface

It is used to configure the hibernate such as DataSource name, Mapping Resources and etc. Hibernate Mapping documents are located using this interface.

Configuration cf= new Configuration();

cf.configure(“hibernate.cfg.xml”);

SessionFactory

It holds a second level cache (optional) of data. A Single session factory is used for the whole application. The org.hibernate.SessionFactory interface provides a factory method to get the object of Session. Session factory is highweight.

SessionFactory sessionFactory= cf.buildSessionFactory();

Session interface

This interface act as an intermediate between application and data hold in the database. Here exists a primary level of cache in hibernate. The instances of this interface can easily be neither created or destroyed. Consists of lightweight object. Sessions in hibernate are not thread-safe.

Session session=sessionFactory.openSession();

Transaction Interface

It is an optional interface. This interface abstracts the code from any kind of transaction implementation. The org.hibernate.Transaction interface provides methods for transaction management.

Transaction t= session.beginTransaction();

TransactionFactory

Its a factory of transaction andIt’s optional too.

Persistent objects and collections

Persistent objects are associated with exactly one org.hibernate.Session. Once the org.hibernate. Session is closed, they will be detached from memory.

Query and Criteria Interface

It allows the user to perform various queries and also control the query execution flow.

Author: STEPS

Leave a Reply

Your email address will not be published. Required fields are marked *