-->
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.  [ 4 posts ] 
Author Message
 Post subject: Join problem: Same object is returned multiple times in List
PostPosted: Tue Apr 18, 2006 8:49 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
I seem to have a strange outer-join situation going on when trying to map a many-to-many association as follows.

SubProject <-- 0.* -------- 0.*--> AttributeDefinition

When I list the SubProjects I get multiple entries for SubProjects for each AttributeDefinition.

ie if a subProject has 4 AttributeDefinitions, I get 4 copies of the SubProject when I run the following code:
Code:
                ICriteria criteria = localSession.CreateCriteria(typeof (SubProject));               
                criteria.Add(Expression.Eq("Project", project));
                criteria.AddOrder(Order.Asc("Name"));
                results = criteria.List();

Does anyone have any ideas as to how to fix this knotty problem?

I have mapped the relationship as follows:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="KBR.LAPD.DocumentManagement.Entities.SubProject, Entities" table="SUB_PROJECT">
    <id name="SubProjectID" column="SUB_PROJECT_ID">

    <!--
     ..... other properties
    -->
   
    <bag name="AttributeDefinitions" table="SUB_PROJ_ATTR_DEF" lazy="false" fetch="join"  outer-join="false" inverse="true">
      <key column="SUB_PROJ_ID"/>
      <many-to-many class="KBR.LAPD.DocumentManagement.Entities.AttributeDefinition, Entities" column="ATTR_DEF_ID" outer-join="false" />
    </bag>
     </class>
</hibernate-mapping>


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="KBR.LAPD.DocumentManagement.Entities.AttributeDefinition, Entities" table="ATTR_DEF">

<!--
  ... other properties
-->

    <bag name="SubProjects" table="SUB_PROJ_ATTR_DEF"   outer-join="false">
      <key column="ATTR_DEF_ID   " />
      <many-to-many class="KBR.LAPD.DocumentManagement.Entities.SubProject, Entities" column="SUB_PROJ_ID" />
    </bag>
      </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 9:39 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
add this to your criteria:
.SetResultTransformer(CriteriaUtil.DistinctRootEntity)

That should help! ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 9:57 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
Yep.. works fine... I would have never found that one! Where on earth is this one documented?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 12:02 pm 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
dircums wrote:
Yep.. works fine... I would have never found that one! Where on earth is this one documented?


it's in the docs and also on the forum, with a search ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.