title: Creating savepoint and rollingback in hibernate
body: <p>How to create a savepoint and how to use rollback if exception occurs  in hibernate I know how it works in jdbc but i got stuck creating savepoint in hibernate program. </p>
  
  <p>My program is 'public class StudentStoredData {
    public static void main(String[] args) {</p>
  
  <pre><code>String name = " ";
  int count = 0;
  int cond = 0;
  // creating configuration object
  Configuration cfg = new Configuration();
  cfg.configure("Student.cfg.xml");// populates the data of the configuration file
  
  
  SessionFactory factory = cfg.buildSessionFactory();
  Session session = factory.openSession();
  Transaction t = session.beginTransaction();
  
  try {
    do {
      Scanner scn = new Scanner(System.in);
      System.out.println("enter 1 to insert and 0 to quit");
      cond = scn.nextInt();
      if (cond == 0)
        break;
      Student e1 = new Student();
  
      System.out.println("Enter Id ");
      int id = scn.nextInt();
      e1.setId(id);
      System.out.println("Enter name ");
      name = scn.next();
      e1.setName(name);
  
      session.persist(e1);// persisting the object
      System.out.println("successfully saved");
  
        t.commit();
  
    } while (cond != 0);
  } catch (Exception e) {
    System.out.println("error occured in saving values . rolling back the recent changes");
    } finally {
    session.close();
  }
  </code></pre>
  
  <p>}
  }
  '
  Their is student class with id and name as attribute and setter and getter method as persistent class. Where do i get the connection variable .. I am new to hibernate .</p>