Tuesday 11 January 2011

Why HibernateSession.flush()


Reference:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html#objectstate-flushing

Default behavior:

Flushing the session forces Hibernate to synchronize the in-memory state of the session with the database but does not commit the changes to database.

Usage:


  • To force database validation (database constraints) and handle the error no need to wait until commit
  • To check duplicate (Force the row to be inserted)
  • To get an assigned id
  • To update the size of session