title: Retrieve an entity without its relationships using JPA without Lazy Loading
body: <p>I have an entity which has <code>OneToMany</code> relationships with other entities such as the <code>Boat</code> entity below. In reality, the entity has <em>many</em> fields.</p>
  
  <pre><code>@Entity
  public class Boat {
      @Id
      private long id;
      private String name;
  
      @OneToMany(fetch=FetchType.EAGER)
      private List&lt;Gun&gt; guns;
  
      public List&lt;Gun&gt; getGuns() {
          return guns;
      }
  
      public String getName() {
          return name;
      }
  }
  </code></pre>
  
  <p>For some searches, I am only interested in the Basic attributes of <code>Boat</code> and do not want to retrieve any <code>OneToMany</code> relationships. One option is to make all <code>OneToMany</code> relationships with <code>fetch=FetchType.LAZY</code>. </p>
  
  <p>However, lazy loading creates two issues:</p>
  
  <ol>
  <li>Lazy loading creates a proxy around the <code>OneToMany</code> relationship which I do not need. I do not need to access the <code>OneToMany</code> relationship <strong>at all</strong> and I need every performance improvement I can get. </li>
  <li>Many other queries require eager fetching, and changing all <code>OneToMany</code> and <code>ManyToOne</code> relationships to lazy fetching would make other queries cumbersome.</li>
  </ol>
  
  <p>Is there a way to choose which relationships should be retrieved dynamically without using lazy fetching. Is this possible using standard JPQL?</p>
  
  <p>I am using EclipseLink in Glassfish.</p>
  
  <p>I have previously investigate EclipseLink fetch groups, which sort of tackles my issue. However, I ran in to this issue: <a href="https://stackoverflow.com/questions/19577864/classdescriptor-returns-null-fetchgroupmanager-when-trying-to-create-an-eclipsel">https://stackoverflow.com/questions/19577864/classdescriptor-returns-null-fetchgroupmanager-when-trying-to-create-an-eclipsel</a></p>