Thankyou for your reply.
I have been working on a Hibernate-Core-only project for some time now and have just started looking into JPA, trying to see where it's the same and where it's different.
In the Hibernate core project we are using the Hibernate.initialize() method in the following situations
- the Collection is rarely needed so mapping it eager is not a desired option
- transparent lazy loading is not an option as the entity is detached
- the method used to load the entity is using HQL for the query and using "left join fetch" on a One-To-Many relation will duplicate rows in the SQL ResultSet.
Our standard approach is as follows
- map almost everything "lazy"
- use explicit HQL for queries, using "left join fetch" for X-To-One relations
- depend on transparent lazy loading while the session is open
- use Hibernate.initialize() for X-To-Many relations, in case the Collections are used after detaching the objects
With this approach using "Hibernate.initialize()" seems logical and I thought something similar would be available in JPA.
Of course we can just access the Collection elements while the session is still open (e.g. getSetOfChildren().size()) for transparent lazy loading, but I think that a dedicated method like "Hibernate.initialize()" is the "cleaner" solution, as it clearly shows the intention.