When you specify lazy="true" on collection elements, hibernate only returns proxy to each of collection objects - in other words, no database query for collection object.
If you close the session and try to access the collection object outside session, you will get LazyInit...Exception. In order to remove such exception either load the collection forcefully in one session by calling Hibernate.initialize( collection ) or connect to a new session with session.lock( mpObject, LockMode.NONE ). There are other options such as session.read(), session.merge() which will take one more query to load the information. Once locking the object in the second session, you can access the collection object without any exception. hope this helps...
|