title: Spring Data JPA Query method duplicates objects
body: <p>I am trying to retrieve a list of objects using a query method in the following way:</p>
  
  <pre><code>@Entity
  public class Cancellation {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Integer id;
  
  
      @OneToMany(mappedBy="cancellation", cascade=CascadeType.ALL)
      @JsonBackReference
      private Set&lt;Schedule&gt; schedules = new HashSet&lt;Schedule&gt;();
  
  }
  
  @Entity
  public class Schedule {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Integer id;
  
      @NotNull
      private Date date;
  
      @NotNull
      private Time time;
  
      @ManyToOne
      @JsonManagedReference
      private Cancellation cancellation;
  
  }
  
  
  
  public interface CancellationRepository extends CrudRepository&lt;Cancellation, 
  Integer&gt; {  
  
      List&lt;Cancellation&gt; findBySchedulesDateGreaterThanEqual(Date date);
  
  }
  </code></pre>
  
  <p>The problem is that the query is returning an object well and the rest returns empty, when only one Cancellation object should be returned within the list. The number of objects that are returned matches the number of Schedules in DB.</p>
  
  <p><a href="https://i.stack.imgur.com/2l2Ri.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2l2Ri.png" alt="In the image in single object Cancelled not empty is the first"></a></p>
  
  <p>In the image in single object Cancelled not empty is the first.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>According to the suggestion of @JBNizet I have changed my method to:</p>
  
  <pre><code>List&lt;Cancellation&gt; findDistinctCancellationBySchedulesDateGreaterThanEqual(Date date);
  </code></pre>
  
  <p>Now works like a charm</p>