title: Hibernate Criteria : selection from two tables with Foreign key relationship?
body: <p>I have in my mysql databse 2 tables : </p>
  
  <pre><code>1.teacher(id(pk),name,phone,email)
  2.student(id(pk),teacher'sid(FK),name,phone,email)
  </code></pre>
  
  <p>The student table has a Foreign Key , teacher'sid ,that refrences to teacher.id .</p>
  
  <p>I want to select the teachers that their id(teachers.id) is same as (student.teacher'sid) where student.name = "Steven".</p>
  
  <p>I have made two classes with the same class name and properties as the table,and i have configured the mapping.</p>
  
  <pre><code>@Entity
  class teacher {
  @Id
  int id;
  String name;
  String phone;
  String email;
  }
  
  @Entity
  class student {
  @Id
  int id;
  int teachersid;
  String name;
  String phone;
  String email;
  }
  </code></pre>
  
  <p>I am able to select the student that his name is "steven" by:</p>
  
  <pre><code>Criteria q = session.createCriteria(student.class).add(
                  Restrictions.eq("name", "stevens"));
  </code></pre>
  
  <p>How can retreive the teacher of "Steven"?
  Something like</p>
  
  <pre><code>(select * from teacher(where teacher.id = student.teachersid(where student.name="stevens")))
  </code></pre>
  
  <p>,but with Hibernate Criteria Api.</p>
  
  <p>Thanks in advance!</p>