title: FetchMode Join vs SubSelect
body: <p>I have two tables Employee and Department following are the entity classes for both of them</p>
  
  <pre><code>Department.java
  @Entity
  @Table(name = "DEPARTMENT")
  public class Department {
      @Id
      @Column(name = "DEPARTMENT_ID")
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer departmentId;
      @Column(name = "DEPARTMENT_NAME")
      private String departmentName;
      @Column(name = "LOCATION")
      private String location;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "department", orphanRemoval = true)
      @Fetch(FetchMode.SUBSELECT)
      //@Fetch(FetchMode.JOIN)
      private List&lt;Employee&gt; employees = new ArrayList&lt;&gt;();
  }
  
  
  Employee.java
  @Entity
  @Table(name = "EMPLOYEE")
  public class Employee {
      @Id
      @SequenceGenerator(name = "emp_seq", sequenceName = "seq_employee")
      @GeneratedValue(generator = "emp_seq")
      @Column(name = "EMPLOYEE_ID")
      private Integer employeeId;
      @Column(name = "EMPLOYEE_NAME")
      private String employeeName;
  
      @ManyToOne
      @JoinColumn(name = "DEPARTMENT_ID")
      private Department department;
  }
  </code></pre>
  
  <p>Below are the queries fired when I did <code>em.find(Department.class, 1);</code></p>
  
  <p><strong>-- fetch mode = fetchmode.join</strong></p>
  
  <pre><code>    SELECT department0_.DEPARTMENT_ID AS DEPARTMENT_ID1_0_0_,
        department0_.DEPARTMENT_NAME    AS DEPARTMENT_NAME2_0_0_,
        department0_.LOCATION           AS LOCATION3_0_0_,
        employees1_.DEPARTMENT_ID       AS DEPARTMENT_ID3_1_1_,
        employees1_.EMPLOYEE_ID         AS EMPLOYEE_ID1_1_1_,
        employees1_.EMPLOYEE_ID         AS EMPLOYEE_ID1_1_2_,
        employees1_.DEPARTMENT_ID       AS DEPARTMENT_ID3_1_2_,
        employees1_.EMPLOYEE_NAME       AS EMPLOYEE_NAME2_1_2_
      FROM DEPARTMENT department0_
      LEFT OUTER JOIN EMPLOYEE employees1_
      ON department0_.DEPARTMENT_ID   =employees1_.DEPARTMENT_ID
      WHERE department0_.DEPARTMENT_ID=?
  </code></pre>
  
  <p><strong>-- fetch mode = fetchmode.subselect</strong></p>
  
  <pre><code>    SELECT department0_.DEPARTMENT_ID AS DEPARTMENT_ID1_0_0_,
        department0_.DEPARTMENT_NAME    AS DEPARTMENT_NAME2_0_0_,
        department0_.LOCATION           AS LOCATION3_0_0_
      FROM DEPARTMENT department0_
      WHERE department0_.DEPARTMENT_ID=?
  
      SELECT employees0_.DEPARTMENT_ID AS DEPARTMENT_ID3_1_0_,
        employees0_.EMPLOYEE_ID        AS EMPLOYEE_ID1_1_0_,
        employees0_.EMPLOYEE_ID        AS EMPLOYEE_ID1_1_1_,
        employees0_.DEPARTMENT_ID      AS DEPARTMENT_ID3_1_1_,
        employees0_.EMPLOYEE_NAME      AS EMPLOYEE_NAME2_1_1_
      FROM EMPLOYEE employees0_
      WHERE employees0_.DEPARTMENT_ID=?
  </code></pre>
  
  <p>I just wanted to know which one should we prefer <code>FetchMode.JOIN</code> or <code>FetchMode.SUBSELECT</code>? which one should we opt in which scenario?</p>