title: Hibernate help with a criteria join query
body: <p>I have four tables, USER, CONTACT, CONACT_TYPE, and USER_CONTACT</p>
  
  <p>USER_CONTACT stores all of the contacts that a user has tables populated with dummy data are as follows</p>
  
  <p><strong>USER TABLE</strong></p>
  
  <pre><code>USER_ID(int)| FIRST_NAME(varchar(2) | LAST_NAME(varchar(2) |
  ------------------------------------------------------------
  |    1      |       TEST            |       USER           |
  ------------------------------------------------------------
  </code></pre>
  
  <p><strong>USER_CONTACT</strong></p>
  
  <pre><code>USER_CONTACT_ID(int) | USER_ID(int) | CONTACT_ID(int) |
  -------------------------------------------------------
  |     1              |       1      |         1       |
  |     2              |       1      |         2       |
  |     3              |       1      |         3       | 
  -------------------------------------------------------
  </code></pre>
  
  <p><strong>CONTACT</strong></p>
  
  <pre><code>CONTACT_ID(int) |  CONTACT_TYPE_ID(int) | CONTACT(varchar(2)|
  -------------------------------------------------------------
  |      1        |         2             |  (555) 555-5555   |
  |      2        |         2             |  (555) 593-3938   |
  |      3        |         1             |  test@oracle.com  | 
  -------------------------------------------------------------
  </code></pre>
  
  <p><strong>CONTACT_TYPE</strong></p>
  
  <pre><code>CONTACT_TYPE_ID(int) | CONTACT_TYPE | 
  -------------------------------------
  |       1            |   EMAIL      | 
  |       2            |   PHONE      | 
  -------------------------------------
  </code></pre>
  
  <p>What I am trying to do is create a query that will return a List that has contains only the PHONE CONACT_TYPE here is my hibernate function so far</p>
  
  <pre><code>public List&lt;UserContact&gt; getUserContactByType(Integer userId, String contactType) {
        Session session = getSessionFactory().openSession();
  
        try {
             Criteria criteria = session.createCriteria(UserContact.class, "USER_CONACT");
  
             criteria.add(Restrictions.eq("USER_CONACT.userId, userId");
  
             criteria.add(Restrictions.eq("USER_CONTACT.contact.contactType.contactType", contactType);
  
             return (List&lt;UserContact&gt;)criteria.list();
  
        }
  
  }
  </code></pre>
  
  <p>Each table is mapped to a model class. The important class information is as follows.</p>
  
  <p><strong>Contact.java</strong></p>
  
  <p>Contains a @ManyToOne relationship to ContactType.java class </p>
  
  <pre><code>@ManyToOne(optional = false, fetch = FetchType.EAGER)
  private ContactType contactType;
  </code></pre>
  
  <p><strong>UserContact.java</strong></p>
  
  <p>Contains a @ManyToOne relationship to Contact.java class and a @ManyToOne on the User.java class</p>
  
  <pre><code>@ManyToOne(optional = false, fetch = FetchType.LAZY)
  private Contact contact;
  
  @ManyToOne(optional = false, fetch = FetchType.LAZY)
  private User user;
  </code></pre>
  
  <p>All of the classes have the standard getters and setters for all of the column attributes for the tables above also.</p>
  
  <p>I keep getting an error stating that it cannot resolve the property contact.contactType  of my UserContact class. Anyone know how to properly execute something like this in hibernate?</p>