Reputation: 722
Got a bit of an unusual problem - i'm sure i'm missing something really simple now! Have two tables in particular:
<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>
and
<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>
I think have a named query in my .HBM.XML file as below:
FROM Proposal MSP
JOIN FETCH MSP.DataItems Items
Unless i'm going nutes, given that the Proposal is a one-to-many with ProposalData, NH should load each of the Proposal objects, and the Data for each as a collection. Unfortunately, i'm ending up with duplicate results, as there are multiple ProposalData for each Proposal.
My understand is this should not be a problem. If ProposalData had a one-to-many with another table, then a Cartesian product would result and the above could be expected.
Am i incorrect? Can anyone shed any light?
Thanks.
Upvotes: 0
Views: 755
Reputation: 64628
JOIN FETCH
means that the items are joined and also used to fetch them. This leads to multiplication of the proposals. Note: the duplicates are still the same instances in memory.
Fix it by using the DistinctRootEntityTransformer
or by avoiding join fetch
.
Upvotes: 1