Easy learning with example program codes

Object states in Hibernate

A persistent class object can be in one of the following three states:

  1. Transient.
  2. Persistent.
  3. Detached.

1. Transient:

A persistent class object is said to be in transient state if it is not associated with hibernate session.

2. Persistent:

A persistent class object is said to be in transient state if it is associated with hibernate session.

3. Detached:

A persistent object becomes detached object when hibernate session is closed.


//Create the student object. Student object is in trabsient state here.
Student student = new Student();
//Setting the object properties.
student.setClassName("MCA final");
//Get the session object.
Session session = HibernateUtil.getSessionFactory().openSession();
//Start hibernate transaction.
//Persist the student object. Student object is in persistence state here.;
//Commit hibernate transaction.
//Close the hibernate session.
// Student object is in detached state here 
//if we want to do any operation on it.

Next Topic: Hibernate mapping file with example.
Previous Topic: Persistent class 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.


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki