44. What is transactional write-behind

Hibernate uses a sophisticated algorithm to determine an efficient ordering that avoids database foreign key constraint violations but is still sufficiently predictable to the user. This feature is called transactional write-behind.


  1. Calling session.save(entity) in the code does not cause an immediate sql insert to be fired. Similarly session.delete(entity) or session.update(entity) will not result immediately in the execution of the sql delete or update queries being fired.
    When objects associated with the persistence context are modified, they are not immediately propagated to the database.
    What Hibernate does is instead collect all such database operations associated with a transaction, creating the minimum set of sql queries and executing them. This gives us two advantages -

    Every property change in the entity does not cause a separate sql update to be executed.
    Avoiding unwanted sql queries ensures minimum trips to database thus reducing the network latency
    In case of multiple updates/inserts or deletes, Hibernate is able to make use of the JDBC Batch API to optimize performance.

    This delayed execution of sql queries is known as transactional write behind. On calling a transaction.commit(), Hibernate flushes all the sql to the database.

  2. Amazing & Great informative blog,it gives very useful practical information to developer like me. Besides that Wisen has established as Best Hibernate Training in Chennai . or learn thru Online Training mode Hibernate Online Training | Java EE Online Training. Nowadays Hibernate ORM has tons of job opportunities on various vertical industry.