title: How to set autocommit to false in hibernate with Spring MVC
body: <p>I'm currently on learning integration of Spring + Hibernate, and so far I'm getting it to work. But I've run into situation where I dont want to commit the transaction at the end of process because I just want to see the generated sql stattement for testing and debugging purposes. </p>
  
  <p>I have already added    false to my hibernate properties, but then It still doesn't working.</p>
  
  <p>Is it possible to achieve if using Spring to handle hibernate transaction? because in using traditional transaction in hibernate , it is possible, just don't call the session.commit() method and all the updates and insert will not be saved;</p>
  
  <p>currently I have this code for my service layer :</p>
  
  <p>@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  public class EmployeeServiceImpl{</p>
  
  <pre><code>@Autowired
  private EmployeeDao employeeDao
  
  @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
  public void saveEmployee(Employee employee){
  
      // count the number of employee in the database
      int n  = employeeDao.getEmployeeCount();
      // lets say it should print 10 here
      System.out.println("number of employee before inserting : " + n);
  
      // insert to employee
      employeeDao.saveEmployee(employee);
  
      // then count the employee after inserting
      n  =  employeeDao.getEmployeeCount();
  
      // then it should print 11 here after inserting new employee
      System.out.println("number of employee after inserting : " + n);
  
  /* Then Dont commit insert!!!
  */
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Code for Dao layer :</p>
  
  <pre><code>public EmployeeDaoImpl implements EmployeeDao{
  
  @Autowired
  public void saveEmployee(Employee employee){
  
      sessionFactory.getCurrentSession.save(employee);
  
  }
  
  public int getEmployeeCount(){
  
      String count = sessionFactory.getCurrentSesion.createQuery("select count(emp.employeeId) from Employee emp")
      .list().get(0).toString;
  
  return Integer.valueOf(count);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But what happens here is that it does commit the transaction!, But I dont want to commit the transaction  just for testing and debugging purposes.</p>
  
  <p>I've also tried
   @Transactional(propagation = Propagation.SUPPORTS, readOnly = false)
  instead of
  @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)</p>
  
  <p>But what happens here is that it does not commit the transaction,  however the count of employee does not also incrementing.</p>
  
  <p>So, what I am expecting to happen here is that count the number of employee before inserting to employee table. Then insert to employee table and count again the number of employee, so it would increment by 1. But at the end of the process , I don't want to commit that insert!</p>
  
  <p>Do you have any Idea guys?</p>
  
  <p>I would be very thankful for any help! 
  Thanks!</p>