title: What is the fastest way to update multiple rows of a table
body: <p>I have a table named <code>messages</code> containing <code>toUser</code>, <code>message</code> and <code>status</code> columns.
  I want to update all the statuses of the messages with a specific user.</p>
  
  <p>So, I wrote a query like this,</p>
  
  <pre><code>Session s = DB.getSession();
  s.createSQLQuery("UPDATE `message` SET `status`='0' WHERE `toUser`='3'").executeUpdate();
  s.close();
  </code></pre>
  
  <p>But then, I was been told that updating using pure hibernate methods are more faster and efficient (I think it has to do something with the hibernate pool), like shown below.</p>
  
  <pre><code>Session s = DB.getSession();
  Transaction tr = s.beginTransaction();
  Criteria cr = s.createCriteria(Connection.Pojo.Message.class);
  cr.add(Restrictions.eq("toUser", 3));
  List&lt;Connection.Pojo.Message&gt; l = cr.list();
  for (Connection.Pojo.Message msg : l) {
      msg.setStatus((byte) 0);
      s.update(msg);
  }
  tr.commit();
  s.close();
  </code></pre>
  
  <p>So, my question is what is the fastest way to update these rows? Please provide a detailed answer if possible.</p>
  
  <p>Thanks in any advice.</p>