title: Spring Data JpaRepository "JOIN FETCH" returns duplicates
body: <p>I'm writing a simple Spring Data JPA application. I use MySQL database. There are two simple tables:</p>
  <ul>
  <li>Department</li>
  <li>Employee</li>
  </ul>
  <p>Each employee works in some department (Employee.department_id).</p>
  <pre><code>@Entity
  public class Department {
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Id
      private Long id;
  
      @Basic(fetch = FetchType.LAZY)
      @OneToMany(mappedBy = &quot;department&quot;)
      List&lt;Employee&gt; employees;
  }
  
  @Entity
  public class Employee {
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Id
      private Long id;
  
      @ManyToOne
      @JoinColumn
      private Department department;
  }
  
  @Repository
  public interface DepartmentRepository extends JpaRepository&lt;Department, Long&gt; {
      @Query(&quot;FROM Department dep JOIN FETCH dep.employees emp WHERE dep = emp.department&quot;)
      List&lt;Department&gt; getAll();
  }
  </code></pre>
  <p>The method <code>getAll</code> returns a list with duplicated departments (each department is repeated as many times as there are employees in this department).</p>
  <p>Question 1: Am I rigth that this is a feature related not to Spring Data JPA, but to to Hibernate?<br />
  Question 2: What is the best way to fix it? (I found at least two ways: 1) use <code>Set&lt;Department&gt; getAll();</code> 2) use <code>&quot;SELECT DISTINCT dep&quot;</code> in <code>@Query</code> annotation)</p>