-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Duplicate records from inner join fetch
PostPosted: Thu Jul 03, 2008 10:07 am 
Newbie

Joined: Thu Jul 03, 2008 7:44 am
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.