title: Hibernate find an existing object in db
body: <p>Simple question here : </p>
  
  <p>If i've got an object with initialized and uninitialized values in it. Is there an <strong>easy way</strong> to find in my db all the Entities that fit this one with hibernate ? (without listing and checking every variable of the object)</p>
  
  <p>Example : </p>
  
  <p>I got this class :</p>
  
  <pre><code>public class User {
      private int id;
      private String name;
      private String email;
      private boolean activ;
  }
  </code></pre>
  
  <p>I would like to be able to do that :</p>
  
  <pre><code>User user1 = new User();
  user.setActive() = true;
  
  User user2 = new User();
  user.setActive(true);
  user.setName("petter")
  
  listUser1 = findAllUser(user1);
  listUser2 = findAllUser(user2);
  </code></pre>
  
  <p>Here listUser1 will contain all the active users and listUser2 will contain all the active user that are named petter.</p>
  
  <p>Thx guys ! </p>
  
  <h2>Edit/Solution</h2>
  
  <p>So my here is my code (i used a class wich is similar at the one of my example).
  It work just fine but the problem is that according to Eclipse : "The method createCriteria(Class) from the type SharedSessionContract is deprecated"...</p>
  
  <pre><code>public static List&lt;Personne&gt; findAllPersonne(Personne personne) {
      List&lt;Personne&gt; listPersonne;
  
      EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("testhibernate0");
      EntityManager entityManager = entityManagerFactory.createEntityManager();
  
      Session session = entityManager.unwrap(Session.class);
  
      Example personneExample = Example.create(personne);
      Criteria criteria = session.createCriteria(Personne.class).add(personneExample);
  
      listPersonne = criteria.list();
  
      entityManager.close();
      return listPersonne;
  }  
  </code></pre>
  
  <p>So .. How could i do that in a better way? I've looked into CriteriaQuery but i can't find how to use it with an example.</p>