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: join fetch returns as many parents as there are children
PostPosted: Tue Nov 23, 2010 9:47 pm 
Newbie

Joined: Tue Nov 23, 2010 9:19 pm
Posts: 1
I have a Parent/Child relationship and I am trying to eagerly fetch the children from the parent without resorting to several SELECTs. I am using
Code:
        final Session session = sessionFactory.getCurrentSession();
       
        final String queryStr = "from  TransactiveNodeInterchangeFlow t join fetch t.intervals ti "
                              + "order by t.sourceId, ti.sinkId, ti.intervalStartTime asc";
        @SuppressWarnings("unchecked")
        List<TransactiveNodeInterchangeFlow> signals = session.createQuery(queryStr).list();

        return signals;


The problem is that I am getting as many parent objects as there are children, this is, if Parent ID=1 has 10 Children, I end up with 10 Parent Instances all of them with ID=1 and the same Children, instead of having a single Parent object (ID=1)

These are my mapping files
Code:
<hibernate-mapping package="com.pnsgdp.data.dataModel">
    <class name="TransactiveNodeInterchangeFlow" table="ETMTRANSMISSIONZONE">
        <id name="id" type="long" column="TRANSMISSIONZONEID" />

        <property name="sourceId" column="TRANSACTIVECONTROLNODENAME" not-null="true" unique="true"/>

        <set name="intervals">
            <key column="FROMTRANSMISSIONZONEID" />
            <one-to-many class="TransactiveNodeInterchangeFlowInterval" />
        </set>
    </class>
</hibernate-mapping>

<hibernate-mapping package="com.pnsgdp.data.dataModel">
    <class name="TransactiveNodeInterchangeFlowInterval" table="R_TCNODEINTERCHANGEFLOW">
        <composite-id>
            <key-many-to-one name="parent" column="FROMTRANSMISSIONZONEID" />
            <key-property name="sinkId" column="TOTCNODENAME" />
            <key-property name="intervalStartTime" column="EFFECTIVETIME" type="com.pnsg.time.hibernate.UTCJDateType" />
        </composite-id>

        <property name="intervalEndTime" column="TERMINATIONTIME" type="com.pnsg.time.hibernate.UTCJDateType" />

        <property name="flow" />
    </class>
</hibernate-mapping>


I do not want to use DISTINCT nor OUTER JOINS. It is a very simple master/detail example. What am I missing?

Thanks


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.