-->
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.  [ 6 posts ] 
Author Message
 Post subject: wrong order of list objects in HQL query
PostPosted: Wed Jun 09, 2004 4:34 pm 
Newbie

Joined: Thu Oct 16, 2003 4:55 am
Posts: 9
Location: Berlin, Germany
hi there,

I am using 2.1.1

I use this mapping:
Code:
   <class name="de.form4.catalog.entities.Catalog" table="KAT_CATALOG">
      <id name="id" column="ID">
         <generator class="increment"/>
      </id>
...
        <list name="doublePageList" table="KAT_CATALOG_DOUBLEPAGE">
            <key>
                <column name="CATALOG_ID" not-null="true"/>
            </key>
            <index column="I"/>
            <many-to-many class="de.form4.catalog.entities.DoublePage">
                <column name="DOUBLEPAGE_ID" not-null="true"/>
            </many-to-many>
        </list>
</class>


I use this query:
Code:
SELECT dp
FROM de.form4.catalog.entities.Catalog AS c
JOIN c.doublePageList AS dp
WHERE c.id = 2


I see this in the hibernate debug:
Code:
222740 [DEBUG] hibernate.SQL (getPreparedStatement.223)  - select doublepage2_.ID as x0_0_, doublepage2_.LEFTLABEL as x1
_0_, doublepage2_.RIGHTLABEL as x2_0_ from KAT_CATALOG catalog0_, KAT_CATALOG_DOUBLEPAGE doublepage1_, KAT_DOUBLEPAGE do
ublepage2_ where catalog0_.ID=doublepage1_.CATALOG_ID and doublepage1_.DOUBLEPAGE_ID=doublepage2_.ID and ((catalog0_.ID=
2 ))
222740 [DEBUG] impl.BatcherImpl (getPreparedStatement.227)  - preparing statement
223461 [DEBUG] loader.Loader (doQuery.196)  - processing result set
223461 [DEBUG] loader.Loader (getRow.404)  - result row:
223502 [DEBUG] type.LongType (nullSafeGet.68)  - returning '14' as column: x0_0_
223502 [DEBUG] type.StringType (nullSafeGet.68)  - returning '1/10' as column: x1_0_
223502 [DEBUG] type.StringType (nullSafeGet.68)  - returning '1/11' as column: x2_0_
223512 [DEBUG] loader.Loader (getRow.404)  - result row:
223512 [DEBUG] type.LongType (nullSafeGet.68)  - returning '15' as column: x0_0_
223512 [DEBUG] type.StringType (nullSafeGet.68)  - returning '11/11/55' as column: x1_0_
223512 [DEBUG] type.StringType (nullSafeGet.68)  - returning '11/11/56' as column: x2_0_
223512 [DEBUG] loader.Loader (getRow.404)  - result row:
223512 [DEBUG] type.LongType (nullSafeGet.68)  - returning '13' as column: x0_0_
223512 [DEBUG] type.StringType (nullSafeGet.68)  - returning '2' as column: x1_0_
223522 [DEBUG] type.StringType (nullSafeGet.68)  - returning '3' as column: x2_0_
223522 [DEBUG] loader.Loader (getRow.404)  - result row:
223522 [DEBUG] type.LongType (nullSafeGet.68)  - returning '12' as column: x0_0_
223522 [DEBUG] type.StringType (nullSafeGet.64)  - returning null as column: x1_0_
223522 [DEBUG] type.StringType (nullSafeGet.68)  - returning '1' as column: x2_0_
223522 [DEBUG] loader.Loader (getRow.404)  - result row:
223522 [DEBUG] type.LongType (nullSafeGet.68)  - returning '16' as column: x0_0_
223522 [DEBUG] type.StringType (nullSafeGet.68)  - returning '1/5' as column: x1_0_
223532 [DEBUG] type.StringType (nullSafeGet.68)  - returning '1/6' as column: x2_0_
223532 [DEBUG] loader.Loader (doQuery.225)  - done processing result set (5 rows)


the problem is:
the order of these objects is random. obviously the index column is not read. I probably can understand this in a manual query, but the same happens when I do:

Code:
Catalog cat = session.load(Catalog.class, new Integer(2));
cat.getDoublePageList();


here too, I get a random order, although the debug shows, that the index column is read.
my question:

How can I get an ordered list from a HQL query ?


thanx a lot in advance for any hints

:olliX


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 5:58 pm 
Newbie

Joined: Sun Apr 11, 2004 12:13 pm
Posts: 7
I'm not exactly sure what you want sorted, but you should be able to use an "order-by" in your mapping file...

Code:

   <class name="de.form4.catalog.entities.Catalog" table="KAT_CATALOG">
      <id name="id" column="ID">
         <generator class="increment"/>
      </id>
...
        <list name="doublePageList" table="KAT_CATALOG_DOUBLEPAGE"  order-by="I"
            <key>
                <column name="CATALOG_ID" not-null="true"/>
            </key>
            <index column="I"/>
            <many-to-many class="de.form4.catalog.entities.DoublePage">
                <column name="DOUBLEPAGE_ID" not-null="true"/>
            </many-to-many>
        </list>
</class>



...or you could just add an order by to your hql statement

Code:
SELECT dp
FROM de.form4.catalog.entities.Catalog AS c
JOIN c.doublePageList AS dp
WHERE c.id = 2
Order by dp.column_name


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 3:05 am 
Newbie

Joined: Thu Oct 16, 2003 4:55 am
Posts: 9
Location: Berlin, Germany
well, since I use a [code]LIST[/code] mapping, I would expect the list to be in the very same order every time, that would be the order defined at the creation of the list. I even tried to order explicitly with the index() function, but that does not work either, because I get an error telling me, that the index property cannot be found.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 3:14 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
olliX wrote:
well, since I use a
Code:
LIST
mapping, I would expect the list to be in the very same order every time, that would be the order defined at the creation of the list. I even tried to order explicitly with the index() function, but that does not work either, because I get an error telling me, that the index property cannot be found.


But databases don't main order do they so you have be explicit about it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 3:17 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:04 pm
Posts: 64
Location: Melbourne, Australia
Sorry... forget I said that. Replied without reading carefully.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 4:02 am 
Newbie

Joined: Thu Oct 16, 2003 4:55 am
Posts: 9
Location: Berlin, Germany
ok,
after some more experimenting and some more reading in the docs, I see, that I can use a one-to-many relation. That means, I can map the index column, which then is in the DoublePage entity, to a property and thus I can order by the index in HQL.
But I wonder, if this is meant to be. I would suppose, that even in an HQL query, the parser should concider the index and always order the items of a List?


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