-->
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.asc() and Order.desc() fail to process sub-properties
PostPosted: Fri Mar 16, 2007 7:59 pm 
Newbie

Joined: Fri Mar 16, 2007 5:52 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

3.2.1GA

Name and version of the database you are using:

MySQL 5.0.27

Problem

Unlike Restrictions, Order.asc(String propertyName) and Order.desc(String propertyName) only seem to be able to process one property level. For instance, where criteria.add(Restrictions.like("property.subproperty", "%foo%") works fine, criteria.addOrder(Order.asc("property.subproperty")) throws an "org.hibernate.QueryException: could not resolve property: ...".

One, where would I report this as a feature request? Two, is there a workaround without resorting to using a Query? (session.createQuery("from Table t order by t.property.subproperty") does work just fine).

Thanks,

Derek


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 11:06 pm 
Newbie

Joined: Fri Mar 16, 2007 10:35 am
Posts: 4
edit: oops, i might have been too fast, you're using MySQL.
if you mean another table by "subproperty", you might want to look into createAlias("tablename", "name for usage")

can you post your mappings and full code to generate the query?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 4:47 pm 
Newbie

Joined: Tue Dec 12, 2006 5:01 am
Posts: 11
Aliases do indeed work. But this is nowhere documented. (The documentation on ordering is actually a joke.) Nor is it in any way intuitive. But from the source code it's obvious that only aliases are working.

I modified Hibernate's CriteriaQueryTranslator to work with association paths as well. Be aware that you need to create the criterias for the associations in advance.

Hope this helps,

Joerg


Top
 Profile  
 
 Post subject: Re: Order.asc() and Order.desc() fail to process sub-properties
PostPosted: Wed Mar 09, 2011 5:19 pm 
Newbie

Joined: Wed Mar 09, 2011 5:14 pm
Posts: 2
Solution is:

Criteria subCriteria = criteria.createCriteria("property");

subCriteria.addOrder(Order.asc("subproperty")) ;


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