title: Efficient Delete in Hibernate
body: <p>I know that the following code will delete the record with id = 5 from database:</p>
  
  <pre><code> Query query = session.createQuery("delete from Class where id = 5");
   query.executeUpdate();
  </code></pre>
  
  <p>But before i delete it, need to save this record's data in a variable.
  So I want to select id = 5, and after some code, I delete it.
  It's not efficient if i use two distinct query for them. Because in this way we search database for this item two times. </p>
  
  <pre><code>query = session.createQuery("from Class where id = 5");
  //somecode
  query = session.createQuery("delete Class where id = 5");
  ...
  </code></pre>
  
  <p>So i need a more efficient way to do this, and do it better.</p>