Spring framework provides HibernateTemplate class
 Don’t worry about creating configuration, creating session factory, transaction, commits
Following are methods of HibernateTemplate class

1) void persist(Object entity)
Saves the given object.

2)Serializable save(Object entity)
Saves the given object and returns id.

3)void saveOrUpdate(Object entity)
Saves or updates the given object. If id is found, it updates the record otherwise saves the record.

4)void update(Object entity)
updates the given object.

5)void delete(Object entity)
deletes the given object on the basis of id.

6)Object get(Class entityClass, Serializable id)
returns the persistent object on the basis of given id.

7)Object load(Class entityClass, Serializable id)
returns the persistent object on the basis of given id.

8)List loadAll(Class entityClass)
returns the all the persistent objects.

Above are HibernateTemplate Methods.

For Spring+Hibernate integration we have to create datasource and pass hibernate.hbm.xml in different way

package bo;

public class StudentBo {
       private int sno;
       private String name;
       private String address;
       public int getSno() {
              return sno;
       public void setSno(int sno) {
              this.sno = sno;
       public String getName() {
              return name;
       public void setName(String name) {
              this.name = name;
       public String getAddress() {
              return address;
       public void setAddress(String address) {
              this.address = address;


package dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import bo.StudentBo;

public class StudentDao {
       private HibernateTemplate template;

       public HibernateTemplate getTemplate() {
              return template;

       public void setTemplate(HibernateTemplate template) {
              this.template = template;
       public void saveData(StudentBo bo){
              System.out.println("Saving : "+bo);
       public void updateData(StudentBo bo){
              System.out.println("updateData : "+bo);
       public void deleteData(StudentBo bo){
              System.out.println("deleteData : "+bo);
       //select all
       public List<StudentBo> selectAll(StudentBo bo){
              List<StudentBo>list = new ArrayList<StudentBo>();           
              list = template.loadAll(StudentBo.class);
              return list;
       //select by id
       public StudentBo selectById(int sno){
              StudentBo ob =       template.get(StudentBo.class, sno);
              return ob;


package main;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import bo.StudentBo;

import dao.StudentDao;

public class StudentMain {
public static void main(String[] args) {
       BeanFactory factory = new ClassPathXmlApplicationContext("res/s.xml");
       StudentDao dao = (StudentDao) factory.getBean("dao");
       StudentBo bo = new StudentBo();

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
<class name="bo.StudentBo" table="student"> 
          <id name="sno"> 
          <generator class="assigned"></generator> 
          <property name="name"></property> 
          <property name="address"></property> 


       <!-- 1. set Properties to DriverManagerDataSource -->
       <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
              <property name="driverClassName" value="com.mysql.jdbc.Driver" />
              <property name="url" value="jdbc:mysql://localhost:3306/test" />
              <property name="username" value="root" />
              <property name="password" value="root" />

       <bean id="mysessionFactory"       class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
              <property name="dataSource" ref="ds"></property>
              <property name="mappingResources">

              <property name="hibernateProperties">
                           <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                           <prop key="hibernate.hbm2ddl.auto">update</prop>
                           <prop key="hibernate.show_sql">true</prop>

       <bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate">
              <property name="sessionFactory" ref="mysessionFactory"></property>

       <bean id="dao" class="dao.StudentDao">
              <property name="template" ref="template"></property>