-->
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: Order by clause, ignored
PostPosted: Mon Jun 04, 2007 9:27 am 
Newbie

Joined: Sun Nov 26, 2006 10:19 am
Posts: 2
Hi

Hibernate version: 3.2.1.ga

Name and version of the database you are using: Mysql 5.0.27

The generated SQL (show_sql=true):
Hibernate:
/* select
i1.propertyEntity ,
i1
from
Property as i1
where
i1.propertyEntity.type = 'orderby' */ select
property0_.propertyEntity_id as col_0_0_,
property0_.id as col_1_0_
from
property property0_,
entity entity1_
where
property0_.propertyEntity_id=entity1_.id
and entity1_.entityType='orderby'


Debug level Hibernate log excerpt:


I'm using hibernate query language to generate some queries. My problems is currently the 'order by' clause. I have generated the following query in HSQL

Code:
INFO: Creating query  select i1.propertyEntity  , i1 from   Property as i1  where i1.propertyEntity.type = 'orderby'  order by i1.dateTime  asc


The problem is that the order by are ignored. I have included the output from hibernate above. No matter if I use order by i1.dateTime asc
or order by i1.dateTime desc the result are returned in the same order. Can somebody help me on whats going on here?

Thanks, Niels


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 10:34 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
It could look silly but what about this HQL:
Code:
select
   ent,
   prop
from
   Property as prop
   inner join prop.propertyEntity as ent
where
   ent.type = 'orderby'
order by
   prop.dateTime  asc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 7:44 am 
Newbie

Joined: Sun Nov 26, 2006 10:19 am
Posts: 2
Hi

Thanks for the reply!

I tried

Code:
INFO: Creating query  select i2  , i1 from   Property as i1 inner join i1.propertyEntity as i2  where i2.type = 'orderby'  order by i1.dateTime  asc


and got the following output from hibernate, it is the same as before. My order clause are removed.

Code:
as suggested
Hibernate:
    /*  select
        i2  ,
        i1
    from
        Property as i1
    inner join
        i1.propertyEntity as i2 
    where
        i2.type = 'orderby'  */ select
            entity1_.id as col_0_0_,
            property0_.id as col_1_0_
        from
            property property0_
        inner join
            entity entity1_
                on property0_.propertyEntity_id=entity1_.id
        where
            entity1_.entityType='orderby'



What are the reason that you suggested the inner join.

Thanks, Niels


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 7:54 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

try criteria.

List list=sess.createCriteria(Property .class,"i1")
.createCriteria("propertyEntity","i2")
.add(Restrictions.eq("i2.type","orderby"))
.addOrder(Order.asc("i1.dateTime"))
.list();


Amila

(Don't forget to rate if helps)


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.