< Prev
Next >



Spring with Hibernate



In this tutorial, we are going to explain how to configure a Spring project to work with Hibernate and perform database operations using Spring Framework such as -

In order to configure Spring Framework with Hibernate to perform database operations, we will use a very important template class provided by Spring Framework which allows us to use Hibernate to perform database operations , named - HibernateTemplate.


Creating the Java class - Customer


We are going to create a java class named Customer within the decodejava package and this class contains - Besides this, we are also going to define a couple of getter and setter methods within this class to set the above mentioned properties of Customer class.


package decodejava;

public class Customer 
{
	private int id;
	private String name;
	private String address;
	private int age;
	
	
	//Default Constructor
	public Customer()
	{
	}
	
	//Parameterized Constructor
	public Customer(int id, String name, String address, int age)
	{
		this.id = id;
		this.name = name;
		this.address= address;
		this.age = age;
	}
	
	
	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;
	}
	
	
	public int getAge() 
	{
		return age;
	}
	
	
	public void setAge(int age) 
	{
		this.age = age;
	}
	
	
	public int getId() 
	{
		return id;
	}


	public void setId(int id) 
	{
		this.id = id;
	}

}





Class performing data access operations using Spring


Next, we are going to add another Java class named CustomerDAO and it is going to contain two properties, such as -
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2