title: Running lazy collection inside a Transaction Still returning LazyInitializationException
body: <p>I have integrated Spring boot with JavaFX application, 
  So anotating class with @Transactional will throw NullPointerException (
  Maybe there a synchronisation problem with FXMLLoader and spring boot)
  Any way i have decided to create a transaction manually using EntityManager.
  My entity has lazy properties, when i try to access a lazy property inside a transaction, i still getting LazyInitializationException.</p>
  
  <p>Code for my entity : </p>
  
  <pre><code>@Entity
  @Table(name = "Product")
  public class Product {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "idproduct")
      private Long idProduct;
  
  @OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true)
      Set&lt;CommercialePieceItem&gt; commercialePieceItems = new HashSet&lt;&gt;();
  
      }
  </code></pre>
  
  <p>I have tried many approches to initialize lazy collection but no thing works</p>
  
  <p>1 try : </p>
  
  <pre><code> @Autowired
      EntityManagerFactory emf;
  
  
    EntityManager entityManager = emf.createEntityManager() ;
                  entityManager.getTransaction().begin();
                  entityManager.merge(product);
                  int qty = product.getCommercialePieceItems().size() ;
                  entityManager.getTransaction().commit();
                  entityManager.close(); ;
  </code></pre>
  
  <p>At line  </p>
  
  <blockquote>
    <p>int qty = product.getCommercialePieceItems().size() ; it throws  a 
    LazyInitializationException</p>
  </blockquote>
  
  <p>Try 2 : </p>
  
  <pre><code> TransactionTemplate transactionTemplate = new TransactionTemplate(platformTransactionManager) ; 
                  transactionTemplate.execute(new TransactionCallback&lt;Object&gt;() {
                      @Override
                      public Object doInTransaction(TransactionStatus transactionStatus) {
                          Hibernate.initialize(product.getCommercialePieceItems());
                          return null;
                      }
                  });
  </code></pre>
  
  <blockquote>
    <p>Also it throws a LazyInitializationException ;</p>
  </blockquote>
  
  <p>Try 3 : i tried to use a helper service : </p>
  
  <pre><code>@Service
  public class DatabaseService {
  
   @Transactional
      public void initializeLazyObject(Object objects) {
          Hibernate.initialize(objects);
  
  
      }
  }
  @Autowired
  DatabaseService databaseservice ; 
  
  databaseservice.initializeLazyObject(product.getCommercialePieceItems()) ; 
  </code></pre>
  
  <p>As always it throws a LazyInitializationException ;</p>
  
  <p>So, what's the problem her ? 
  How can i fix this LazyInitializationException  in Spring Data JPA ? </p>