title: what is difference between hibernateTemplate Flush() and clear() methods?
body: <p>what is difference between hibernateTemplate flush() and clear() method? which one to use when? </p>
  
  <p>I have following code</p>
  
  <pre><code>    public void saveAllReportRoomRes(List&lt;ReportRoomRes&gt; reportRoomResList) throws  DataAccessException {
      hibernateTemplate.saveOrUpdateAll(reportRoomResList);
      hibernateTemplate.flush();
      }
  </code></pre>
  
  <p>I call this method in loop which passes list of records(total records can be more than 2 lacs) each time. because my code is under transaction, sometime in subsequent iteration, if hibernate found same primary key (I have composite primary key) object, it is throwing NonUniqueObject Exception. but actually it needs to update the record which was inserted before. </p>
  
  <p>If I user HibernateTemplate.clear(), it is working. </p>
  
  <p>Also is it good way to save or Update large amount of records? as this is my usual case where I am copying data from one DB to another DB at certain interval. </p>