A persistent class object can be in one of the following three states:
A persistent class object is said to be in transient state if it is not associated with hibernate session.
A persistent class object is said to be in transient state if it is associated with hibernate session.
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.setFirstName("Vivek"); student.setLastName("Solenki"); student.setClassName("MCA final"); student.setRollNo("MCA/07/70"); student.setAge(27); //Get the session object. Session session = HibernateUtil.getSessionFactory().openSession(); //Start hibernate transaction. session.beginTransaction(); //Persist the student object. Student object is in persistence state here. session.save(student); //Commit hibernate transaction. session.getTransaction().commit(); //Close the hibernate session. session.close(); // Student object is in detached state here //if we want to do any operation on it.