title: How to fetch only selected attributes of an entity using Spring JPA?
body: <p>I'm using Spring Boot (1.3.3.RELEASE) and Hibernate JPA in my project. My entity looks like this:</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @Entity
  @Table(name = "rule")
  public class RuleVO {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @Column(name = "name", length = 128, nullable = false, unique = true)
      private String name;
  
      @Column(name = "tag", length = 256)
      private String tag;
  
      @OneToMany(mappedBy = "rule", cascade = CascadeType.ALL, orphanRemoval = true)
      private List&lt;RuleOutputArticleVO&gt; outputArticles;
  
      @OneToMany(mappedBy = "rule", cascade = CascadeType.ALL, orphanRemoval = true)
      private List&lt;RuleInputArticleVO&gt; inputArticles;
  }
  </code></pre>
  
  <p>My repository looks like this:</p>
  
  <pre><code>@Repository
  public interface RuleRepository extends JpaRepository&lt;RuleVO, Long&gt; {
  }
  </code></pre>
  
  <p>In some cases I need to fetch only <strong>id</strong> and <strong>name</strong> attributes of entity RuleVO. How can I achieve this? I found a notice it should be doable using Criteria API and Projections but how? Many thanks in advance. Vojtech</p>