SPRING WITH HIBERNATE
Java

SPRING WITH HIBERNATE

SPRING WITH HIBERNATE

Spring is a lightweight framework. It can be thought of as a framework of frameworks because it provides support to various frameworks such as Struts, Hibernate, Tapestry, EJB, JSF, etc. Where as Hibernate (open source, lightweight, Object Relational Mapping tool) is a Java framework that simplifies the development of Java application to interact with the database. We can use these two frameworks, in order to reduce the complexity in software application development. Spring provides an API to easily integrate Spring with ORM frameworks such as Hibernate. Since there are a lot of versions of Spring and Hibernate both and Spring ORM artifact supports both Hibernate 3 and Hibernate 4.

Suppose We need to plug in the spring framework in our web application, that is done by configuring Spring framework DispatcherServlet as the front controller. For a user to develop spring hibernate mvc application, they must need to use POJO (Plain Old Java Object) classes, their corresponding Hibernate Mapping file(mapping. hbm. xml), Web XML page, Data access Object(DAO) classes and their implementation Interfaces.

Hibernate SessionFactory can be configured in the Spring bean configuration file itself. You need not have a separate hibernate configuration file (hibernate. cfg. xml) to do this. All the Hibernate-related configurations can be done using the hibernateProperties. We use a separate DAO class to interact with the database. Using a setter or constructor injection, we inject the Hibernate SessionFactory. We have a MultiActionController class to handle the web requests from the clients.

The hibernate Template makes the task of querying much easier, by providing methods such as save(), update(),delete(),load(), loadAll(). Templates saves the Object into the database. The storage and retrieval of data are much simpler while using, Spring Hibernate integration MVC.

The Spring framework provides HibernateTemplate class, that allows users not to follow so many steps like creating Configuration, BuildSessionFactory, Session, beginning and committing the transaction, etc. By Integrating Spring with Hibernate, developers can save lots of code.

Author: STEPS

Leave a Reply

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