-->
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: Too many instances returned from Criteria.list()
PostPosted: Fri Jan 27, 2006 1:59 am 
Newbie

Joined: Wed Mar 23, 2005 1:02 pm
Posts: 4
Hibernate version:
3.0 Final

Mapping documents:
parent class:
Code:
<class
    name="AirSigmet"
    table="AirSigmets">
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="AirSigmets"
    </meta>

    <id
        name="airSigmetId"
        type="java.lang.Integer"
        column="airSigmetId" >
        <meta attribute="field-description">
           @hibernate.id
            generator-class="native"
            type="java.lang.Integer"
            column="airSigmetId"
        </meta>
        <generator class="native" />
    </id>
    <!-- Associations -->
    <set name="pointsSet" table="AirSigmetsPoints" sort="natural" lazy="false" inverse="false" fetch="join">
       <key column="airSigmetId"/>
       <one-to-many class="AirSigmetsPoint"/>
    </set>
</class>


Points class:
Code:
<class
    name="AirSigmetsPoint"
    table="AirSigmetsPoints"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="AirSigmetsPoints"
    </meta>

    <composite-id name="comp_id" class="AirSigmetsPointPK">
        <meta attribute="field-description" inherit="false">
           @hibernate.id
            generator-class="native"
        </meta>
        <key-property
            name="airSigmetId"
            column="airSigmetId"
            type="java.lang.Integer"
            length="10">
            <meta attribute="field-description">
               @hibernate.property
                column="airSigmetId"
            </meta>
        </key-property>
</class>



Name and version of the database you are using:
MySQL 3.23.49

The generated SQL (show_sql=true):
Hibernate: /* criteria query */ select this_.airSigmetId as airSigme1_8_1_, this_.icaoId as icaoId8_1_, this_.alphaChar as alphaChar8_1_, this_.receiptTime as receiptT4_8_1_, this_.creationTime as creation5_8_1_, this_.validTimeFrom as validTim6_8_1_, this_.validTimeTo as validTim7_8_1_, this_.airSigmetType as airSigme8_8_1_, this_.hazard as hazard8_1_, this_.severity as severity8_1_, this_.altitudeLow1 as altitud11_8_1_, this_.altitudeLow2 as altitud12_8_1_, this_.altitudeHi1 as altitudeHi13_8_1_, this_.altitudeHi2 as altitudeHi14_8_1_, this_.movementDir as movemen15_8_1_, this_.movementSpd as movemen16_8_1_, this_.rawAirSigmet as rawAirS17_8_1_, this_.postProcessFlag as postPro18_8_1_, pt1_.airSigmetId as airSigme1_9_0_, pt1_.pointIdx as pointIdx9_0_, pt1_.lat as lat9_0_, pt1_.lon as lon9_0_ from AirSigmets this_ inner join AirSigmetsPoints pt1_ on this_.airSigmetId=pt1_.airSigmetId where (this_.validTimeFrom<=? and this_.validTimeTo>=?) order by this_.receiptTime desc
Hibernate: /* load one-to-many AirSigmet.pointsSet */ select pointsset0_.airSigmetId as airSigme1_1_, pointsset0_.pointIdx as pointIdx1_, pointsset0_.airSigmetId as airSigme1_9_0_, pointsset0_.pointIdx as pointIdx9_0_, pointsset0_.lat as lat9_0_, pointsset0_.lon as lon9_0_ from AirSigmetsPoints pointsset0_ where pointsset0_.airSigmetId=?
...


The issue I'm running into is that I am getting back a much larger number of my parent class than should be coming back. Criteria.list() returns me a List of 425 objects, when only 30 or so have actually been instantiated when I print them out. Does anyone know what I'm doing wrong here? It appears to be repeatedly inserting the same objects into the List for some reason before giving it to me. I assume this is something simple, but I can't find any documentation regarding this issue.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:19 am 
Newbie

Joined: Thu Jan 26, 2006 2:13 pm
Posts: 9
Hi braeckel

Try it again by using

Code:
Collection result = new HashSet(criteria.list());


This will create a new HashSet which does not allow an entry to be double. I don't know where I got this from, but I read somewhere that this can occur when Hibernate searches on fetched tables.

Hope this helps.


--
carpe diem


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 7:10 am 
Newbie

Joined: Thu Jan 26, 2006 6:19 am
Posts: 19
carpeDiem wrote:
Hi braeckel

Try it again by using

Code:
Collection result = new HashSet(criteria.list());


This will create a new HashSet which does not allow an entry to be double. I don't know where I got this from, but I read somewhere that this can occur when Hibernate searches on fetched tables.

Hope this helps.


--
carpe diem


The reason it occurs is, although you create the criteria using new Criteria(AirSigmet.class), when you introduce the linked table, it puts all the fields in linked table to the select part of query. This makes all rows unique, althogh its not..
I have the same problem and I wrote a method to filter repeating objects.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 1:01 pm 
Newbie

Joined: Thu Jan 26, 2006 6:19 am
Posts: 19
By the way:

Code:
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


may solve your problem.

dont forget to rate:)

onur wrote:
carpeDiem wrote:
Hi braeckel

Try it again by using

Code:
Collection result = new HashSet(criteria.list());


This will create a new HashSet which does not allow an entry to be double. I don't know where I got this from, but I read somewhere that this can occur when Hibernate searches on fetched tables.

Hope this helps.


--
carpe diem


The reason it occurs is, although you create the criteria using new Criteria(AirSigmet.class), when you introduce the linked table, it puts all the fields in linked table to the select part of query. This makes all rows unique, althogh its not..
I have the same problem and I wrote a method to filter repeating objects.


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.