title: Distinct counting with Spring JPA repository
body: <p>Now I'm counting views of topic something like this: </p>
  
  <pre><code>Long countByViewOnTopicId(Long topicId);
  </code></pre>
  
  <p>This is equivalent to SQL query</p>
  
  <pre><code>select count(*) from views where topic_id = ? 
  </code></pre>
  
  <p>This gives me the number of all views, but I need to count the number of unique users. I need JPA equivalent of below query:</p>
  
  <pre><code>select count(distinct user_id) from views where topic_id = ?
  </code></pre>
  
  <p>I can use the <code>@Query</code> annotation, but I'm trying to write less custom SQL in the project. Like below:</p>
  
  <pre><code>Long countDictinctUserIdByViewOnTopicId(Long topicId);
  </code></pre>
  
  <p><strong>Update:</strong>
  `Below entry details:</p>
  
  <pre><code>@Entity
  @Table(name = "views")
  public class Views {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @NotNull
      @Column(name = "user_id", insertable = false, updatable = false)
      private Long userId;
  
      @JoinColumn(name = "user_id")
      @ManyToOne
      private User user;
  
      @NotNull
      @Column(name = "topic_id", insertable = false, updatable = false)
      private Long topicId;
  
      @JoinColumn(name = "topic_id")
      @ManyToOne
      private Topic topic;
  
      @NotNull
      @Column(name = "action_type")
      @Enumerated(EnumType.ORDINAL)
      private ActionTypes actionType;
  
  Getter, Setter...
  </code></pre>