Since the permissions collection was not initialized when the Session was closed, the collection will not be able to load its state. Hibernate does not support lazy initialization for detached objects.
posted 9 years ago
Any pointers why the above code will give exception
There is no open session when you access your collection. The collection has not been initialized because (presumably) it is configured for lazy initialization (?) and there is no mechanism not to initialize it.
Without seeing how you've mapped this I can't say, but I'll guess your collection related to an association in the database? In which case Hibernate will try to load this if it is not already loaded. And it will fail if there is no open Session to use.
Indeed it is. How is it related to your question? Are you using the second level cache? If you are then you understand that something has to put object into this cache in the first place, and nothing in your code does that.