title: How to fetch object via spring data(jpql) that is in relation via next other object
body: <p>I'm using spring data with JPQL grouping select, everything works and stats are counted, but when I want to acces to competition object I'm getting this error:</p>
  
  <pre><code>org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  </code></pre>
  
  <p>I have these entities that I want to collect for stats</p>
  
  <pre><code>@Entity
  public class BetCourse {
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "MATCH_ID", nullable = false)
      private BetMatch betMatch;
  }
  
  @Entity
  public class BetMatch {
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "betMatch")
      private List&lt;BetCourse&gt; courses = new ArrayList&lt;&gt;();
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "COMPETITION_ID", nullable = false)
      private Competition competition;
  }
  
  @Entity
  public class Competition {
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "competition")
      private List&lt;BetMatch&gt; betMatches = new ArrayList&lt;&gt;();
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "competition")
      private List&lt;Stats&gt; stats = new ArrayList&lt;&gt;();
  }
  </code></pre>
  
  <p>And I'm digging data from these classes to the Stats class</p>
  
  <pre><code>@Entity
  public class Stats {
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "COMPETITION_ID", nullable = false)
      private Competition competition;
  }
  </code></pre>
  
  <p>via this select:</p>
  
  <pre><code>@Query("select new Stats(" +
              "c.course, " +
              "c.courseType, " +
              "count(*), " +
              "SUM(CASE WHEN win = true THEN 1 ELSE 0 END), " +
              "c.betMatch.competition) " +
              "from BetCourse c " +
              group by c.course, c.betMatch.competition, c.courseType")
      public List&lt;Stats&gt; computeStatsByBetShop();
  </code></pre>
  
  <p>and when I acces to competiton object</p>
  
  <pre><code>stat.getCompetition()
  </code></pre>
  
  <p>How can I fetch this object? Is it possible to somehow combine with join fetch?</p>