According to the documentation, an inner join fetch on a class containing a set should return an object of that class type containing all objects within the set. I am getting multiple objects of the class, one for each object in the set and the set does contain all of its objects. So, if there's 1 record of class A and the child set contains 5 elements, I get duplicate 5 objects each containing the 5 elements in the set. Here's what I have.
MailingInstance class:
Code:
<hibernate-mapping>
<class name="MailingInstance" table="MailingInst">
<id name="mailingInstanceId" type="long">
<column name="MailingInstID" />
<generator class="assigned" />
</id>
<property name="mailingInstanceType" type="java.lang.Integer">
<column name="MIType" />
</property>
<property name="mailingInstanceStatus" type="java.lang.Integer">
<column name="MIStatusID" />
</property>
... more properties ...
<set name="mailingInstanceLinks" inverse="true" cascade="persist,delete,delete-orphan" fetch="select" lazy="false">
<key>
<column name="MailingInstID" not-null="true" />
</key>
<one-to-many class="MailingInstanceLink" />
</set>
</class
<query name="MailingInstance.GetNotExpiredMailingInstancesWithMILinks_MSSQL">
<![CDATA[
select mi
from MailingInstance mi
inner join fetch mi.mailingInstanceLinks
where mi.logHistoryLevel = :logHistoryLevel
and ((mi.trackLinksDuration = 0) or (mi.finishDate is null) or (mi.trackLinksDuration > DATEDIFF(day, mi.finishDate, current_date())))
]]>
</query>
</hibernate-mapping>
The MailingInstanceLink class:
Code:
<hibernate-mapping>
<class name="MailingInstanceLink" table="MILinks">
<composite-id name="id" class="MailingInstanceLinkPK">
<key-property name="linkId" type="int">
<column name="LinkID" />
</key-property>
<key-property name="mailingInstanceId" type="long">
<column name="MailingInstID" />
</key-property>
</composite-id>
<property name="linkUrl" type="string">
<column name="LinkURL" length="256" />
</property>
<property name="linkDisplayText" type="string">
<column name="LinkDisplayText" length="256" />
</property>
<property name="purgeDate" type="timestamp">
<column name="PurgeDate" length="23" />
</property>
<property name="addAdditionalURLParms" type="int">
<column name="AddAdtlParms" />
</property>
<property name="trackLink" type="int">
<column name="TrackLink" />
</property>
</class>
</hibernate-mapping>
Note: The class attribute was stripped down for clarity. They do contain the fully qualified path.
If I have 1 record in the database of a MailingInstance and that entry is linked to 5 records in the MailingInstanceLink table, when I call the query in the MailingInstance class file, I get 5 duplicates. Am I doing something wrong? Is the query correct? Is there something wrong in the mappings?
Thanks,
Rob