Is there a way to check if a collection is already initialized? try-catch only?
try-catch
I have a function that works with a lazy collection, and I need to load it only if it is not already loaded.
Use Hibernate.initialize(collection) This will initialize the collection if it is not already created.
Hibernate.initialize(collection)
(There is another method - Hibernate.isInitialized(collection) , but since you want to actually load the collection, initialize(..) is the path that performs the same check before proceeding with initialization)
Hibernate.isInitialized(collection)
initialize(..)