Spring HibernateTempate Example

By | June 24, 2021

In this post, We will learn about Spring HibernateTempate Example using a Demo Project.

In hibernate framework, we usually provide all the database information in the hibernate.cfg.xml file.

But when we integrate the hibernate application with spring, we really don’t need to create the hibernate.cfg.xml file. We can configure all the information in the applicationContext.xml file.


We need to add Spring, Hibernate and MySQL dependencies in Maven pom.xml file


Employee entity class to store employee data


Employee Service Interface


Employee Service Implementation class


Employee DAO(Data Access Object) Interface


Employee DAO(Data Access Object) Interface implementation class to perform CRUD operations with MySQL database.


In this config file, we are providing all the information of the database in the DriverManagerDataSource object. This object is used in the LocalSessionFactoryBean class object, containing some other information such as packagesToScan and hibernateProperties. The object of LocalSessionFactoryBean class is used to inject in org.springframework.orm.hibernate5.HibernateTemplate in EmployeeDaoImpl class using setter based dependency injection


This ClientTest class gets the bean from the applicationContext.xml file and calls the different methods of  EmployeeService to perform CRUD operation with MySQL database.

If you run ClientTest.java as Java Application then it will give the below output: 

That’s all about Spring HibernateTempate Example

You May Also Like:

Spring BeanFactory Container Example
Spring ApplicationContext Container Example
Annotation-based Configuration in Spring Framework Example
Spring Java-based Configuration Example
Spring Setter Dependency Injection Example
Spring @Autowired Annotation With Setter Injection Example
Spring Constructor based Dependency Injection Example
Spring @Autowired Annotation With Constructor Injection Example
Spring Autowiring byName & byType Example
getBean() overloaded methods in Spring Framework
Spring Inner bean example
Spring Dependency Injection with Factory Method
Spring Framework @Qualifier example
Injecting Collections in Spring Framework Example
Spring Bean Definition Inheritance Example
Spring bean scopes with example
Spring JSR-250 Annotations with Example
Spring BeanPostProcessor Example
Spring JDBC Integration Example
Spring JDBC Annotation Example
Spring with Jdbc java based configuration example
Spring JDBC NamedParameterJdbcTemplate Example
How to call stored procedures in the Spring Framework?
Spring 5 and Hibernate 5 integration CRUD Example

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

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