Quote:
What about lazy fatching of associations ?
If I close the session, when I try to access a associated class, hibernate throw an Exception (it says that the connection is closed).
The way I understand this (I've been trying to understand how to do some of this for a while, too) is that you need to fully initialize whatever you want to send to the client side before closing the session. This would commonly be done by using fetching strategies in the Query (part of the HQL itself)/Criteria APIs or by simply "walking" the object graph before you send it.
What I am unsure about is whether the retrieved entities (after the session is closed they "become" detached entities) are Serializable. If I understand all of this, if they are serializable as POJOs (when used outside of hibernate, that is), then the proxies that hibernate generates will also be Serializable. Of course, if the client calls a getter on a lazy-loaded property that is not initialized, you will get a LazyInitializationException, but this is why you have to make sure you've initialized everything you want to use
before closing the session.