We are using Hibernate2.1.3 as a MBean in JBoss-3.2.3. We are running into issues related to lazy loading. We have set lazy=true on the collections of a parent objects. But, even then, when the parent object is loaded, the collection is also getting populated with the child objects. Following is a sample hbm mapping:
When we are loading the com.dbdata.core.hibernateobject.Channel (Parent) object, even the collection "channelInstances" is getting populated with instances of com.dbdata.core.hibernateobject.ChannelInstance.
We did a bit of investigation into this and tried to obtain a Thread dump from one of the setters of the child object, to find out the flow from where this setter of the child is getting called. Following is the output from the Thread.dumpStack() invoked from one of the setters of the child object:
It appears that while loading the parent(through Loader.loadEntity) Hibernate invokes the doQueryAndInitializeNonLazyCollections. We had a look at this code and it looks like it intializes the collection irrespective of whether it is lazy=true or lazy=false. Also, the javadoc of this method does not say anything about the lazy attribute:
* Execute an SQL query and attempt to instantiate instances of the class mapped by the given
* persister from each row of the <tt>ResultSet</tt>. If an object is supplied, will attempt to
* initialize that object. If a collection is supplied, attempt to initialize that collection.
Are we missing something here? The lazy=true is a very fundamental feature and it appears that we are surely missing something in our configuration. Any help is appreciated.