title: Hibernate vs Spring connection acquisition strategy
body: <p>I'm trying to understand when exactly a database connection is aquired in an application that uses hibernate as an ORM &amp; Spring for transaction management.</p>
  <p>In <a href="https://dzone.com/articles/what-is-the-difference-between-hibernate-and-sprin-1" rel="nofollow noreferrer">this</a> article, it says:</p>
  <blockquote>
  <p>If the transaction manager decides to create a new transaction, then it will:</p>
  <p>create a new entity manager</p>
  <p>bind the entity manager to the current thread</p>
  <p>grab a connection from the DB connection pool</p>
  <p>bind the connection to the current thread</p>
  </blockquote>
  <p>However <a href="https://vladmihalcea.com/hibernate-aggressive-connection-release/" rel="nofollow noreferrer">here</a> it says :</p>
  <blockquote>
  <p>Hibernate defers the database connection acquisition until the current transaction has to execute its first SQL statement (either triggered by a read or a write operation). This optimization allows Hibernate to reduce the physical transaction interval, therefore increasing the chance of getting a connection from the pool.</p>
  </blockquote>
  <p>I can't understand how can Hibernate delay the connection aquisition if Spring decides to aquire it before.</p>