-->
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.  [ 3 posts ] 
Author Message
 Post subject: Order By with Criteria
PostPosted: Wed May 23, 2007 8:33 am 
Newbie

Joined: Fri Oct 29, 2004 9:39 am
Posts: 5
Hibernate version: 3.2

Name and version of the database you are using: Oracle 10g


I have the following classes with properly mapped HBM files:

Code:
public class Workbench {
   Long id;
   Tool tool;
   public Tool getTool();
}

public class Tool {
   Long id;
   String name;
   public String getName();
}


If I try to do the following in code:

DetachedCriteria criteria = DetachedCriteria.forClass(Workbench.class)
.addOrder( Property.forName("tool.name").asc() );

I get the following error:

HibernateQueryException: could not resolve property: tool.name

Is this a limitation of Hibernate, in that you can't sort on a joined record using Criteria? It seems to work ok with HQL.

_________________
Chris


Top
 Profile  
 
 Post subject: Answer
PostPosted: Wed May 23, 2007 8:58 am 
Newbie

Joined: Fri Oct 29, 2004 9:39 am
Posts: 5
OK, I found the answer:

Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Workbench.class)
   .createAlias("tool", "t")
   .addOrder( Property.forName("t.name").asc() );


However, not a single example on the web that I previously looked at actually shows this, and nor does the documentation. I happened to find this by more thoroughly looking through the forums here.

_________________
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 9:06 am 
Senior
Senior

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


Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Workbench.class,"w").createCriteria("tool").addOrder( Property.forName("name").asc() );



Amila

(Don't forget to rate if it helps)


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