title: How to fetch only some fields of an entity having associations using hibernate query?
body: <p>I have an entity which has multiple fields, some of which are associations. 
  Assume the entity has similar structure to the following:</p>
  
  <pre><code>@Entity
  @Table(name="foos")
  public class Foo {
  
    public Foo() {}
    @Id
    private Long id;
  
    @Column
    private String name;
  
    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "bar_id")
    private Bar bar;
  
    @ManyToOne
    @JoinColumn(name = "bar1_id")
    private Bar1 bar1;
  
    @ManyToOne
    @JoinColumn(name = "bar2_id")
    private Bar2 bar2;
  
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn(name = "foo_id")
    private List&lt;Bar3&gt; bar3;
  
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn(name = "foo_id")
    private List&lt;Bar4&gt; bar4;
  
    //getters and setters
  }
  </code></pre>
  
  <p>My question is how can I load only some fields and not the whole entity using Hibernate query?<br>
  I want to fetch only id, bar, bar1 and bar3, and don't want to fetch the remaining fields(name, bar2, bar4) in the created Foo object.<br>
  I'm pretty new to Hibernate so any advice will be appreciated.</p>