title: Hibernate AUTO flush strategy order
body: <p>I have 2 methods that exhibit a different behavior in regard to flushing in Hibernate.</p>
  
  <p>The first one is: </p>
  
  <pre><code>    @Transactional
      public void firstMthod(int id, int status) {
          Person entity = session.get(Person.class, id);
          entity .setStatus(personStatus.registered);
          session.merge(entity);
          updatePersonAge(id,18);
      }
  </code></pre>
  
  <p>The <code>updatePersonAge</code> method is located in another class, and the SQL output of this method looks like this:</p>
  
  <pre><code>select personel0_.ID            as ID1_119_0_,
         personel0_.status        as status2_119_0_,
         personel0_.age           as age3_119_0_,
         personel0_.CreatedBy     as CreatedBy4_119_0_,
         personel0_.UpdatedBy     as UpdatedBy5_119_0_,
         personel0_.CreatedDate   as CreatedDate6_119_0_,
         personel0_.UpdatedDate   as UpdatedDate7_119_0_,
         personel0_.Ip            as Ip8_119_0_
    from tbl_personel personel0_
   where personel0_.ID = ?
  update tbl_person set status = ? where ID = ?
  update tbl_person set age = ? where ID = ?
  </code></pre>
  
  <p>and for the second use case, we have the following method: </p>
  
  <pre><code>    @Override
      @Transactional
      public void secondMethod(int id,int courseId, int status) {
          Course courseEntity=session.get(Course .class, courseId); 
          courseEntity.setCreatedDate(new Date());
           session.merge(courseEntity);
          updatePersonAge(id,18);
      }
  </code></pre>
  
  <p>For which the <code>updatePersonAge</code> method generates the following SQL output:</p>
  
  <pre><code>select course0_.ID          as ID1_120_0_,
         course0_.CreatedBy   as CreatedBy7_120_0_,
         course0_.UpdatedBy   as UpdatedBy8_120_0_,
         course0_.CreatedDate as CreatedDate9_120_0_,
         course0_.UpdatedDate as UpdatedDate10_120_0_,
         course0_.Ip          as Ip11_120_0_
    from tbl_course course0_
   where course0_.ID = ?
  update tbl_course set created_date = ? where ID = ?
  update tbl_person set age = ? where ID = ?
  </code></pre>
  
  <p>The <code>updatePersoneAge</code> method is : </p>
  
  <pre><code>public int updatePersonAge(int id,int age){
          Query query = session.createQuery("update " + domainClass.getName() + " e set e.age= :age ");
                  query.setParameter("age ", age);
                  return query.executeUpdate();
          }
  </code></pre>
  
  <p>According to my expectations, the output of the second method should be the same with the output of the first method. So why the difference? It is really confusing.</p>