title: Is Persistence.getPersistenceUtil a simpler way of testing whether a lazy loaded JPA collection is initialized when using Spring Boot repositories
body: <p>This question is given an answer here - <a href="https://stackoverflow.com/questions/4306463/how-to-test-whether-lazy-loaded-jpa-collection-is-initialized">How to test whether lazy loaded JPA collection is initialized?</a></p>
  <p>The answer given there makes use of <code>PersistenceUnitUtil</code>. However, in order to get a PersistenceUnitUtil you need to access the EntityManagerFactory. Spring framework uses repositories to hide all that EntityManager stuff, which makes that solution awkward (but not impossible).</p>
  <p>However there is a standard JPA way of accessing a similar object <code>PersistenceUtil</code> - just as <code>Persistence.getPersistenceUtil</code> - which provides an object with the same methods used in the above answer.</p>
  <p>In the Spring framework, using repositories, this appears to be a much simpler way to access those helpful <code>isLoaded</code> methods.</p>
  <p>Is there is any reason not to use that simpler approach?</p>