title: How to test whether lazy loaded JPA collection is initialized?
body: <p>I have a service that gets a JPA entity from outside code. In this service I would like to iterate over a lazily loaded collection that is an attribute of this entity to see if the client has added something to it relative to the current version in the DB.</p>
  
  <p>However, the client may have never touched the collection so it's still not initialized. This results in the well known </p>
  
  <p><code>org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.SomeEntity.</code></p>
  
  <p>Of course, if the client never touched the collection, my service doesn't have to check it for possible changes. The thing is that I can't seem to find a way to test whether the collection is initialized or not. I guess I could call <code>size()</code> on it and if it throws <code>LazyInitializationException</code> I would know, but I'm trying not to depend on such patterns.</p>
  
  <p>Is there some <code>isInitialized()</code> method somewhere?</p>