title: How to force commit entity in @Transactional mode
body: <p>I am using Spring data jpa and jdbc (using entityManager.unwrap(Session.class) ) connection.<br>
  My request flows through 3 method. 1st -> 2nd ->3rd.<br>
  1st and 3rd are annotated with @Transactional.<br>
  In 1st and 2nd method saving entity through JPA CRUD repository.<br>
  In 3rd method using basic jdbc query to retrieve values saved in 2nd method.<br>
  As we know in @Transaction entities are not committed to database until JPA commit the transaction.<br>
  I used saveAndFlush also in 2nd method but can not see retrieve updated values in method 3 using jdbc query.</p>
  
  <p><strong>1st Method - update()</strong></p>
  
  <pre><code>@Transactional
  @Override
  public ApiResponse update(RequestInput input) {
      ApiResponse response = doRestOfWork(input);   // calling 2nd method
      // .... some other entity save....
  }
  </code></pre>
  
  <p><strong>2nd Method - doRestOfWork()</strong> : setting status=true and calling saveAndFlush method</p>
  
  <pre><code>@Override
  public ApiResponse doRestOfWork(Request request) {
      Insight insight = insightRepository.findOne(request.getTypeId());
      insight.setStatus(true);
      insightRepository.saveAndFlush(insight);
  
      processOperation();    // calling 3rd method
  }
  </code></pre>
  
  <p><strong>3rd method - processOperation()</strong> : retrieving updated status value through jdbc connection.</p>
  
  <pre><code>@Transactional
  public void processOperation() {
  Connection conn = null;
          SessionImplementor sessionImpl = (SessionImplementor) entityManager.unwrap(Session.class);
          try {
              conn = sessionImpl.getJdbcConnectionAccess().obtainConnection();
              Connection conn = null;
              String stmt = "SELECT status from insight";
              PreparedStatement ps = conn.prepareStatement(stmt);
              ResultSet rs = ps.executeQuery();
              while (rs.next()) {
                 boolean value = rs.getBoolean(status);   // returning false, i want this to return true as already set true in 2nd method and called saveAndFlush 
          }
      } catch (SQLException ex) {
      } finally {
          JdbcUtility.closeResources(conn, ps, rs);
      }
  }
  </code></pre>
  
  <p><strong>InsightRepository</strong> is extending JpaRepository</p>
  
  <pre><code>@Repository
  public interface InsightRepository extends JpaRepository&lt;Insight, Long&gt; {}
  </code></pre>
  
  <blockquote>
    <p>I want updated value of status (which is boolean true - updated in method 2) in method 3.
    How to achieve this ?</p>
  </blockquote>
  
  <p><strong>Update</strong>   </p>
  
  <p>I searched a lot and do not think that if a method is annotated with  <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html" rel="nofollow noreferrer">@Transactional</a> then you can commit changes before completing JPA transaction. So the solution is to remove <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html" rel="nofollow noreferrer">@Transactional</a> annotation and use entityManager.getTransaction() if want to control over JPA transaction.</p>