title: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: FQPropretyName, could not initialize proxy - no Session
body: <p>I am trying a ManyToOne Bi-Directional Association using SpringBoot, SpringDataJpa along with a unit test using SpringBootTest. However the test fails with the stacktrace shown below. However I am Unable to find the reason. Any pointers will be helpful</p>
  
  <p>Below Spring Boot JUnit Test for ManyToOne Bi-Directional Association fails. </p>
  
  <pre><code>    @Test
      public void testFindByRegionIdEquals() {
          Region region = regionService.findByRegionIdEquals(1L);
          Region expectedRegion = new Region(1L, "Europe");
          assertThat(region).isNotNull().isEqualTo(expectedRegion);
          assertThat(region.getCountries()).isNotEmpty().doesNotContainNull().size().isEqualTo(8);
      }
  </code></pre>
  
  <p><strong><em>Exception StackTrace</em></strong></p>
  
  <pre><code>    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: zikzakjack.domain.Region.countries, could not initialize proxy - no Session
      at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:587)
      at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:204)
      at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148)
      at org.hibernate.collection.internal.PersistentSet.isEmpty(PersistentSet.java:149)
      at org.assertj.core.util.IterableUtil.isNullOrEmpty(IterableUtil.java:35)
      at org.assertj.core.internal.Iterables.assertNotEmpty(Iterables.java:152)
      at org.assertj.core.api.AbstractIterableAssert.isNotEmpty(AbstractIterableAssert.java:145)
      at zikzakjack.service.RegionServiceTests.testFindByRegionIdEquals(RegionServiceTests.java:68)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  </code></pre>
  
  <p><strong><em>Owning Entity ManyToOne</em></strong></p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "COUNTRIES")
  public class Country implements Serializable, Comparable&lt;Country&gt; {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @Column(name = "COUNTRY_ID")
      private String countryId;
  
      @Column(name = "COUNTRY_NAME")
      private String countryName;
  
      @ManyToOne
      @JoinColumn(name = "REGION_ID")
      private Region region;
  
      public Country() {
  
      }
  
      public Country(String countryId, String countryName, Region region) {
          super();
          this.countryId = countryId;
          this.countryName = countryName;
          this.region = region;
      }
  
  }
  </code></pre>
  
  <p><strong>*Non - Owning Entity OneToMany with mappedBy *</strong></p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "REGIONS")
  public class Region implements Serializable, Comparable&lt;Region&gt; {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "REGION_ID")
      private Long regionId;
  
      @Column(name = "REGION_NAME")
      private String regionName;
  
      @OneToMany(mappedBy = "region", fetch = FetchType.LAZY)
      private Set&lt;Country&gt; countries = new HashSet&lt;Country&gt;();
  
      public Region() {
      }
  
      public Region(Long regionId, String regionName) {
          this.regionId = regionId;
          this.regionName = regionName;
      }
  
      public Region(String regionName) {
          this.regionName = regionName;
      }
  
      public void addCountry(Country country) {
          countries.add(country);
          country.setRegion(this);
      }
  }
  </code></pre>