I have three entity classes:Operator,Mailbox and MailboxFolder
relationship: operator to mailbox is one-to-many and mailbox to mailboxFolder is one-to-many too, and both set lazy to true,but when I set show_sql to true ,I found that when I call operator.getMailBoxSet without call MailBox.getFolderSet(), hibernate try to read all mailBox for this operator,but the confused thing is: hibernate try to read all mailBoxFolder for each mailBox too!
the codes:
Iterator iter = operator.getMailBoxSet().Iterator();while(iter.hasNext()){MailBox mailBox=(MailBox)iter.next();logger.debug(mailBox.getID())};
according to hibernat reference,if mailBox.getFolderSet dosen't be called,it's foldSet property should still be lazy collection.
and I also tested such a case: if I use hql to load all mailBox for this operator,lazy-load works fine.
any one could help? thanks very much.
Mapping files:
<class name="com.sinohotel.module.operator.data.Operator" table="operator"
dynamic-update="true" dynamic-insert="true">
<set name="mailBoxSet" table="operator_mailbox" lazy="true" cascade="none" batch-size="5">
<key column="operator_id"/>
<many-to-many class="com.sinohotel.module.mail.data.MailBox" column="mailbox_id"/>
</set>
</class>
<class name="com.sinohotel.module.mail.data.MailBox" table="mailbox"
dynamic-update="true" dynamic-insert="true">
<set name="folderSet" cascade="all,delete-orphan" inverse="true" lazy="true" batch-size="5">
<key column="mailbox_id"/>
<one-to-many class="com.sinohotel.module.mail.data.MailBoxFolder"/>
</set>
</class>
<class name="com.sinohotel.module.mail.data.MailBoxFolder" table="mailbox_folder"
dynamic-update="true" dynamic-insert="true">
<id name="id" type="int">
<column name="id" sql-type="int" not-null="true"/>
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="name" sql-type="char(255)"/>
</property>
<many-to-one name="mailBox" class="com.sinohotel.module.mail.data.MailBox" column="mailbox_id"/>
</class>
|