title: Hibernate Criteria for entity with embedded objects
body: <p>I have an entity "UserDetails" which has the following variables:</p>
  
  <ol>
  <li>String userId</li>
  <li>String userName</li>
  <li>UserContact userContact (where UserContact is an Embeddable class)</li>
  </ol>
  
  <p>UserContact has the following variables:</p>
  
  <ol>
  <li>String phoneNumber </li>
  <li>String email </li>
  <li>String city</li>
  </ol>
  
  <p>What will be a Hibernate Criteria for fetching the following list:</p>
  
  <p>Users with userName = 'sam' and with city = 'New York'</p>
  
  <p>I tried the following and got the runtime exception that it doesn't recognize the variable 'city':</p>
  
  <pre><code>List&lt;UserLogin&gt; list = session.createCriteria(UserLogin.class)
      .add(Restrictions.eq("userName","sam"))
      .add(Restrictions.eq("city", "New York"))
      .list();
  </code></pre>