title: Prevent SQL injection with Hibernate
body: <p>I'm going through Hibernate and I know that you can prevent SQL injection with HQL:</p>
  
  <pre><code>String query1 = "from Obj where id = "+ id;
  String query2 = "from Obj where id = :id";
  </code></pre>
  
  <p><code>query1</code> is unsafe while <code>query2</code> is safe.</p>
  
  <p>How can I achieve safe queries with Criteria? Is this already implemented or do I have to do something else?</p>
  
  <pre><code>Criteria c = session.createCriteria(Obj.class);
  c.add(Restrictions.eq("id", 5));
  </code></pre>