views:

38

answers:

1

Hi all, there is a way to test if a collection is already initialized? try-catch only?

I have a function work with a lazy collection, and i need to load it only if is not already loaded.

Thanks you.

+3  A: 

Use Hibernate.initialize(collection) This will initialize the collection if it is not yet.

(There is another method - Hibernate.isInitialized(collection), but since you want to actually load the collection, initialize(..) is the way to go - it makes the same check before proceeding to initialization)

Bozho
Thank you. Did you mean Hibernate.isInitialized(collection)?
blow
@blow - no. Check my update for clarification
Bozho
@Bozho: this is great! thank you.
blow
That's just exactly what the OP is looking for. +1
Pascal Thivent