-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multiple Parents per child
PostPosted: Tue May 03, 2005 8:56 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Hibernate version:=3

Mapping documents:
Code:
<class
    name="com.sys.dao.bean.PairxordBean"
    table="PAIRXORD"
>
   <id name="ordid" column="ORDID" type="java.lang.Long" unsaved-value="0">
       <generator class="native">
        </generator>
    </id>
       <set name="pairxdets"
             inverse="true"
             cascade="all-delete-orphan">
           <key column="ORDID" />
           <one-to-many class="com.sys.dao.bean.PairxdetBean"/>
        </set>   
        <property
            name="orddattim"
            column="ORDDATTIM"
            type="java.sql.Date"
            length="10"
        />
... other mappings

<class
    name="com.sys.dao.bean.PairxdetBean"
    table="PAIRXDET"
>
   <id name="detid" column="DETID" type="java.lang.Long" unsaved-value="0">
       <generator class="native">
        </generator>
    </id>
       <many-to-one
          name="pairxordBean"
          column="ordid"
          class="com.sys.dao.bean.PairxordBean"
          not-null="true" />

... other mappings


Code
Code:


         List l = sess.createCriteria(PairxordBean.class)
                  .add(Restrictions.eq("reqbyid",paiuserBean.getUserid()))
                  .add(Restrictions.eq("sent",iSent))
                  .setFetchMode("pairxdets",FetchMode.JOIN)
                  .setFetchMode("hmembpBean",FetchMode.JOIN)
                  .list();


With the above mappings and fetching can someone tell me why my I get a PairxordBean object for EVERY PairxdetBean object? In my data base I have one record in the Pairxord table and 2 records in the Pairxdet record with the ordid key equal to the single record in Pairxord. I expected that Hibernate would return one PairxordBean object with a set of two Pairxdet objects in the pairxdets SET. What I get back is two PairxordBean objects that both have the correct pairxdets set in them. Why is this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 11:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
You need to use
Code:
List l = sess.createCriteria(PairxordBean.class)
        .setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY )
        ...
        .list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 11:23 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Thanks! That worked!!


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

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.