• October 14, 2014
  • Hibernate
  • Comments Off on Persistent class

Persistent class

Persistent classes are those java classes whose objects have to be stored in the database tables. They should follow some simple rules of Plain Old Java Object programming model (POJO).

Some rules that should be, not must be followed by a persistence class.

  1. 1. A persistence class should have a default constructor.
  2. 2. A persistence class should have an id to uniquely identify the class objects.
  3. 3. All attributes should be declared private.
  4. 4. Public getter and setter methods should be defined to access the class attributes.



 * This class represents a persistent class for Student.
 * @author javawithease
public class Student {
	//data members
	private int studentId;
	private String firstName;
	private String lastName;
	private String className;
	private String rollNo;
	private int age;
	//no-argument constructor
	public Student(){
	//getter and setter methods
	public int getStudentId() {
		return studentId;
	public void setStudentId(int studentId) {
		this.studentId = studentId;
	public String getFirstName() {
		return firstName;
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	public String getLastName() {
		return lastName;
	public void setLastName(String lastName) {
		this.lastName = lastName;
	public String getClassName() {
		return className;
	public void setClassName(String className) {
		this.className = className;
	public String getRollNo() {
		return rollNo;
	public void setRollNo(String rollNo) {
		this.rollNo = rollNo;
	public int getAge() {
		return age;
	public void setAge(int age) {
		this.age = age;

Next Topic: Object states in Hibernate with example.
Previous Topic: Hibernate configuration file with example.

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.


Comments are closed.