title: How can I configure Hibernate to immediately apply all saves, updates, and deletes?
body: <p>How can I configure <a href="http://www.hibernate.org/" rel="noreferrer">Hibernate</a> to apply all saves, updates, and deletes to the database server immediately after the session executes each operation?  By default, Hibernate enqueues all save, update, and delete operations and submits them to the database server only after a <code>flush()</code> operation, committing the transaction, or the closing of the session in which these operations occur.</p>
  
  <p>One benefit of immediately flushing database "write" operations is that a program can catch and handle any database exceptions (such as a <a href="http://docs.jboss.org/hibernate/core/3.3/api/index.html?org/hibernate/exception/ConstraintViolationException.html" rel="noreferrer">ConstraintViolationException</a>) in the code block in which they occur.  With late or auto-flushing, these exceptions may occur long after the corresponding Hibernate operation that caused the SQL operation.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>According to the Hibernate API documentation for interface <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/Session.html" rel="noreferrer">Session</a>, the benefit of catching and handling a database exception before the session ends may be of no benefit at all: "If the Session throws an exception, the transaction must be rolled back and the session discarded. The internal state of the Session might not be consistent with the database after the exception occurs."</p>
  
  <p>Perhaps, then, the benefit of surrounding an "immediate" Hibernate session write operation with a try-catch block is to catch and log the exception as soon as it occurs.  Does immediate flushing of these operations have any other benefits?</p>