-->
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.  [ 2 posts ] 
Author Message
 Post subject: In trouble with Ordering
PostPosted: Wed Aug 30, 2006 6:09 am 
Newbie

Joined: Wed Aug 30, 2006 5:57 am
Posts: 3
Hibernate version: 3.1

With the following class

Code:

class Parent {
    private Child child;

    // getters and setters ...
}

class Child {
    private String name;

    // getters and setters ...
}



I'm trying to do this "order by"

Code:

Criteria query = session.createCriteria(Parent.class);
query.addOrder(Order.desc("child.name"));

query.list();



but i get this Exception:
Code:
(org.hibernate.QueryException) org.hibernate.QueryException: could not resolve property: child.name of: Parent


How can i solve this ?


Top
 Profile  
 
 Post subject: Try an association alias
PostPosted: Mon Sep 04, 2006 6:58 am 
Newbie

Joined: Mon Sep 04, 2006 6:53 am
Posts: 1
An association alias worked for me in a similar case:

query.createAlias("child", "c");
query.addOrder(Order.desc("c.name"));

where an alias can even be equal to the association name:

query.createAlias("child", "child");
query.addOrder(Order.desc("child.name"));


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