states of object in hibernate

Q. What are the states of object in hibernate?

Update later

Types of Object state in hibernate – 

  1.  Transient
  2.  Persistent
  3.  Detached

Suppose we have one entity

package simpleentity;

import javax.persistence.*;

@Table(name = "book")
public class Book implements Serializable{
	private static final long serialVersionUID = 1L;

	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "book_id")
	private int bookId;

	@Column(name = "book_name")
	private String bookName;

	public String getBookName() {
		return bookName;

	public void setBookName(String bookName) {
		this.bookName = bookName;

	public int getBookId() {
		return bookId;

	public void setBookId(int bookId) {
		this.bookId = bookId;

We also have hibernate.cfg.xml.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="connection.username">SYSTEM</property>
<property name="connection.password">oracle</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">true</property>
<property name="">create</property>
<mapping class="simpleentity.Book" />



We have main class.

package onetoonetechhelpzones;

import org.hibernate.*;
import org.hibernate.cfg.Configuration;

public class ObjectStateExample {
	public static void main(String[] args) {
		SessionFactory factory = null;
		Session session = null;
		Configuration configuration = new Configuration().configure();
		try {
			factory = configuration.buildSessionFactory();
			session = factory.openSession();
			Transaction tx = session.beginTransaction();
			Book b = new Book();
			b.setBookName("book name 1");;

			System.out.println("transaction completed ");
		} catch (Exception e) {

		} finally {