title: Hibernate getNamedQuery executes other UPDATE TABLE
body: <p>I have a code like this. This a legacy code i know maybe is not the best one.</p>
  
  <pre><code>final Student student = loadStudentById(13);
  student.setLastAccessedTime(new Date());
  student.setNote(20);
  updateWithHQLUsingNamedQueries(student);//HERE WE UPDATE BOTH FIELDS USING NAMEDQUERIES
  
   private void updateWithHQLUsingNamedQueries(final Student student){
       final Query query = session.getNamedQuery("namedQuery"); 
       query.setParameter("lastAccessedTime",student.getLastAccessedTime());
       query.setParameter("note",student.getNote());
       query.setParameter("c01",c01Field);
       query.executeUpdate();//HERE HIBERNATE UPDATE THE STUDENT LIKE session.update(student);
   }
  </code></pre>
  
  <p>Also we are using </p>
  
  <pre><code>@org.hibernate.annotations.DynamicUpdate(value=true)
  @org.hibernate.annotations.SelectBeforeUpdate(value=true)
  </code></pre>
  
  <p>Everything works OK but in the SQL logging i can see two updates the first like a regular update like this.</p>
  
  <p>A HIBERNATE UPDATE </p>
  
  <pre><code>update com.models.Student HIBERNATE MESSAGE
  update student set lastAccessedTime=:time and note=:note where id=:id
  </code></pre>
  
  <p>And later i see the update of the namedQueries</p>
  
  <pre><code>update student set c01=:c01 and lastAccessedTime=:time and note=:note where id=:id
  </code></pre>
  
  <p>My question is?</p>
  
  <p>Why Hibernate commits the Student fields in a regular update i mean like i was doing something like just before the executeUpdate? The student is not commited anywhere.</p>
  
  <pre><code>session.update(student);
  </code></pre>
  
  <p>I know they are updating only the dirty fields because i am using DynamicTrue and maybe the last update(NamedQuery) seems wasted. But WHY Hibernate commits the student object like a regular update??? Resulting in two updates? degrading performance?</p>
  
  <p>Thanks to @coladit for your answer but if i modify my code setting a another property like this</p>
  
  <pre><code>final Student student = loadStudentById(13);
  student.setLastAccessedTime(new Date());
  student.setNote(20);
  student.setAnotherProperty(value);//THIS CHANGE IS PERSISTED IN DB
  </code></pre>
  
  <p>Does flush do the property persisted in DB????? Because i modify the property and is updated into the DB even when the namedQuery doesn't persisted..</p>