-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL Distinct behaviour
PostPosted: Wed May 12, 2004 5:13 am 
Newbie

Joined: Fri Apr 16, 2004 11:48 am
Posts: 18
Hibernate descriptor:

Code:
<hibernate-mapping>
    <class
        name="com.cdo.Rating"
        table="RATING"
        dynamic-update="false"
        dynamic-insert="false"
        mutable="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="native">
            </generator>
        </id>

        <set
            name="defaultProbabilities"
            lazy="true"
            inverse="false"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="ratingId"
              />

              <one-to-many
                  class="com.db.gm.risk.vo.cdo.DefaultProbability"
              />
        </set>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Rating.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


HQL query:

Code:
SELECT DISTINCT rating from com.db.gm.risk.vo.cdo.Rating AS rating join fetch rating.defaultProbabilities as defaultProbability"


The above query returns duplicates. If I remove the fetch no duplicates. Am I missing something?

Many thanks!!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 7:53 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
If you fetch a collection Hibernate does not return a distinct result list!
Maybe a useful walkaround:
to get distinct object you can put the result List in a Set:
List result=session.find(...);
Set distinctResult=new HashSet(result);


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