title: Spring boot Unable to evaluate the expression Method threw 'org.hibernate.LazyInitializationException' exception. using getter, ManyToMany relation
body: <p>I've got two classes <strong>Participant</strong> and <strong>TimeWindow</strong>.
  Multiple participants can register for multiple TimeWindow, hence the ManyToMany relation</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table
  public class Participant {
      @Id
      @SequenceGenerator(
              name = &quot;participant_sequence&quot;,
              sequenceName = &quot;particant_sequence&quot;,
              allocationSize = 1
      )
      @GeneratedValue(
              strategy = GenerationType.SEQUENCE,
              generator = &quot;participant_sequence&quot;
      )
      private Long id;
      private String name;
      private String number;
      private String details;
  
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(name = &quot;ParticipantCreneaux&quot;)
      private Collection&lt;TimeWindow&gt; registeredTimeWindow;
  
  
      public Participant() {
  
      }
      public Participant(String nom, String num, String details) {
          this.name = nom;
          this.number = num;
          this.details = details;
          this.registeredTimeWindow = new ArrayList&lt;&gt;();
      }
      public void addTimeWindow(TimeWindow c){
          registeredTimeWindow.add(c);
      }
      public void removeTimeWindow(TimeWindow c){
          registeredTimeWindow.remove(c);
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getNumber() {
          return number;
      }
  
      public void setNumber(String number) {
          this.number = number;
      }
  
      public String getDetails() {
          return details;
      }
  
      public void setDetails(String details) {
          this.details = details;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public Long getId() {
          return id;
      }
  
      public Collection&lt;TimeWindow&gt; getRegisteredTimeWindow() {
          return registeredTimeWindow;
      }
  }
  </code></pre>
  <p>And the TimeWindow class:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table
  public class TimeWindow {
      @Id
      @SequenceGenerator(
              name = &quot;creneau_sequence&quot;,
              sequenceName = &quot;creneau_sequence&quot;,
              allocationSize = 1
      )
      @GeneratedValue(
              strategy = GenerationType.SEQUENCE,
              generator = &quot;creneau_sequence&quot;
      )
      private Long id;
      private LocalTime hourStart;
      private LocalTime hourEnd;
  
      public Collection&lt;Participant&gt; getListParticipants() {
          return listParticipants;
      }
  
      @ManyToMany(fetch = FetchType.LAZY,cascade=CascadeType.ALL,mappedBy = &quot;registeredTimeWindow&quot;)
      private Collection&lt;Participant&gt; listParticipants;
  
      public TimeWindow(LocalTime hourStart, LocalTime hourEnd) {
          this.hourStart = hourStart;
          this.hourEnd = hourEnd;
          this.listParticipants = new ArrayList&lt;&gt;();
      }
  
      public TimeWindow() { }
  
      public LocalTime getHourEnd() {
          return hourEnd;
      }
  
      public void setHourStart(LocalTime hourStart) {
          this.hourStart = hourStart;
      }
  
      public void setHourEnd(LocalTime hourEnd) {
          this.hourEnd = hourEnd;
      }
  
      public LocalTime getHourStart() {
          return hourStart;
      }
  
      public int getNbParticipants(){
          return listParticipants.size();
      }
      public void addParticipant(Participant participant){
          this.listParticipants.add(participant);
      }
      public void removeParticipant(Participant participant){
          this.listParticipants.remove(participant);
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public Long getId() {
          return id;
      }
  }
  </code></pre>
  <p>Right now I'm still learning Spring boot, I haven't found anything about it so far or anything that helped me.</p>
  <p>The error is when I summon my participant's TimeWindow Collection that i've gotten through the DataBase in the Config class. In the debugger my Participant looks like this</p>
  <pre><code>id:123
  name:&quot;hisName&quot;
  number:&quot;321&quot;
  details:&quot;some details&quot;
  registeredTimeWindow:{PersistentBag@10927}Unable to evaluate the expression Method threw 'org.hibernate.LazyInitializationException' exception.
  </code></pre>
  <p>At first i thought it was normal because of the Lazy option, i had to invoke the array through the getter, however it is wrong and the getter give me the exact same object.</p>
  <p>FetchType.EAGER works fine, however I can't afford to do it. I've tried to get some help from someone a bit more experienced than I am, but without success. It should be possible to work around that issue within the JPA Repositories, but it feels like such a waste not to be able to use the getter.</p>