title: Hibernate @OneToOne executes multiple queries even with @Fetch(FetchMode.JOIN)
body: <p>Consider and <code>Employee</code> and <code>Address</code> relationship. There is a One-to-one mapping between <code>Employee</code> and <code>Address</code>. Following are models:</p>
  
  <pre><code>@Entity
  @Table(name = "Address")
  public class Address
  {
      @Id
      @GeneratedValue
      @Column(name = "addressId")
      private int addressId;
  
      @Column(name = "city")
      private String city;
  
      .
      .
  }
  
  @Entity
  @Table(name = "Employee")
  public class Employee
  {
      @Id
      @Column(name = "employeeId")
      private int employeeId;
  
      @Column(name = "name")
      private String name;
  
      @OneToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "addressId")
      @Fetch(FetchMode.JOIN)
      private Address address;
  
      .
      .
  }
  </code></pre>
  
  <p>Now when I execute following HQL query it internally generates two queries. One to fetch Employee and another to fetch Address.</p>
  
  <p><code>"FROM Employee WHERE id = " + 1</code></p>
  
  <p>SQL queries generated by Hibernate</p>
  
  <p><code>Hibernate: select employee0_.employeeId as employeeId0_, employee0_.addressId as addressId0_, employee0_.name as name0_ from Employee employee0_ where employee0_.employeeId=1</code></p>
  
  <p><code>Hibernate: select address0_.addressId as addressId1_0_, address0_.city as city1_0_ from Address address0_ where address0_.addressId=?</code></p>
  
  <p>As I am using <code>@Fetch(FetchMode.JOIN)</code>, I was expecting Hibernate to execute only 1 query with a join to fetch Employee and Address data in one go.</p>
  
  <p>Any idea why it is executing two queries and how can I make Hibernate to execute only one query using join?</p>
  
  <p>I am using Hibernate 3.3.0.</p>