title: Hibernate: check if object exists
body: <p>Suppose, objects of type <i>A</i> are stored in DB. Here's the way I load specific one from DB using hibernate:</p>
  
  <pre><code>org.hibernate.Session session = ...;
  long id = 1;
  A obj = session.load(A.class, id);
  </code></pre>
  
  <p>If object with id=1 doesn't exist I will get <i>ObjectNotFoundException</i>. But is there a way to check if such object exists without having to catch the exception? What I would like to have is smth like:</p>
  
  <pre><code>org.hibernate.Session session = ...;
  long id = 1;
  boolean exists = session.exists(A.class, id);
  if(exists){
   // do smth.....
  }
  </code></pre>
  
  <p>Couldn't find it hibernate docs...</p>