遇到了一个不寻常的问题 - 我确定我现在错过了一些非常简单的东西!特别有两个表:
<class name="Proposal" table="Proposal">
<id name="Id" column="ProposalId">
<generator class="identity" />
</id>
<property name="QuotationNumber" column="QuotationNumber" access="nosetter.camelcase-underscore" />
<set name="DataItems" table="ProposalData" inverse="true" cascade="save-update" access="nosetter.camelcase-underscore" lazy="true">
<key column="ProposalId" />
<one-to-many class="Fortron.Fastr.Domain.Proposal.ProposalData, Fortron.Fastr.Domain"/>
</set>
</class>
和
<class name="ProposalData" table="ProposalData">
<id name="Id" column="ProposalDataId">
<generator class="identity" />
</id>
<many-to-one name="Proposal" column="ProposalId" class="Fortron.Fastr.Domain.Proposal.Proposal, Fortron.Fastr.Domain" />
</class>
我认为在我的 .HBM.XML 文件中有一个命名查询,如下所示:
FROM Proposal MSP
JOIN FETCH MSP.DataItems Items
除非我要疯了,否则考虑到提案与提案数据是一对多的,NH 应该加载每个提案对象,并将每个提案的数据作为一个集合加载。不幸的是,我得到了重复的结果,因为每个提案都有多个 ProposalData。
我的理解是这应该不是问题。如果 ProposalData 与另一个表是一对多的,那么将产生笛卡尔积,并且可以预期上述情况。
我不正确吗?任何人都可以解释一下吗?
谢谢。