-->
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: Problem with 'Order By'
PostPosted: Fri May 13, 2005 10:04 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:3.0[/b]

[b]Mapping documents:[/b]

[b]Code between sessionFactory.openSession() and session.close():
session = HibernateUtil.currentSession();
session.connection().setAutoCommit(true);
Query query = session.createQuery("FROM User u WHERE u.isDeleted = :isDeleted ORDER BY u.name");
query.setParameter("isDeleted", new Boolean(false));
Iterator iterate = query.list().iterator();
while (iterate.hasNext())
{
User user = (User)iterate.next();
System.out.println("userName: " + user.getName());
}
[/b]

[b]Full stack trace of any exception that occurs:[/b]

[b]Name and version of the database you are using:postgresql 8.0[/b]

[b]The generated SQL (show_sql=true):
Hibernate: select user0_.id as id, user0_.name as name2_, user0_.description as descript3_2_, user0_.password as password2_, user0_.is_admin
as is5_2_, user0_.login_date as login6_2_, user0_.locked_date as locked7_2_, user0_.last_ip as last8_2_, user0_.is_deleted as is9_2_ from s
msc_user user0_ where (user0_.is_deleted=?) order by user0_.name
[/b]

[b]Debug level Hibernate log excerpt:[/b]

Hi, am actually doing a simple query where there is an order by. But I never get my data in an ordered way.
Here are my results:

userName: parabole
userName: new_user
userName: radio
userName: gul2
userName: gulshan

Can anyone please help me solve my problem
thanks in advance


Top
 Profile  
 
 Post subject: Re: Problem with 'Order By'
PostPosted: Fri May 13, 2005 4:27 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
gulshan wrote:
Hi, am actually doing a simple query where there is an order by. But I never get my data in an ordered way.
Here are my results:

userName: parabole
userName: new_user
userName: radio
userName: gul2
userName: gulshan

Can anyone please help me solve my problem
thanks in advance


What happens if you run the generated query in against the database using an interactive query tool ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 1:14 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
I got the results in an ordered way.


Top
 Profile  
 
 Post subject: Order by + Iterate Problem
PostPosted: Fri Jul 29, 2005 3:34 pm 
Newbie

Joined: Thu Apr 29, 2004 10:22 am
Posts: 5
Location: Ribeir
I found a bug at a query that use order by and retrieved by iterate().

I have other similar code but accessed by list() and its fine.

Do someone know something about it? It's my mistake or a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 1:05 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
A list is an ordered collection. So when you iterate through your 'query' you'll obtain the items in order if you've specified the 'order by'


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 11:50 am 
Beginner
Beginner

Joined: Thu Jul 28, 2005 6:40 pm
Posts: 29
You didn't say what database you are using but I know that the Oracle JDBC drivers had a problem with order by. The sql would work fine using any other tool - it was just through their JDBC drivers that the problem existed.

This was about 8 months ago (don't remember the details about it) so they could very well have this fixed by now.

thanks - dave


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.