-->
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.  [ 5 posts ] 
Author Message
 Post subject: problem ordering multi-table select using criteria
PostPosted: Fri Dec 16, 2005 10:21 am 
Newbie

Joined: Fri Dec 16, 2005 9:51 am
Posts: 3
Hello everybody !
As you can see, I am new on this forum. I am also new to hibernate.
I have a problem that may be very simple, but after 2 days reading documentations, I don't seem to find any answer :-(.

Here is my situation :
Hibernate version: 2.1.7
Mapping documents:
http://jerome.duquennoy.fr/tmp/DBSoftware.hbm.xml
and
http://jerome.duquennoy.fr/tmp/DBSoftwa ... on.hbm.xml

Code between sessionFactory.openSession() and session.close():
Criteria criteria = session.createCriteria(DBSoftwareVersion.class());
criteria.addOrder(Order.asc("software.name"));
result = criteria.list();

Resulting error
I get an HibernateException with this message :
could not resolve property: software.name of: com.rte.myapp.data.model.DBSoftwareVersion

Problem description :
I have a DBSoftwareVersion object that references a DBSoftware object (many to one).
I need to load a DBSoftwareVersion list, ordered by the names of the associated softwares.

It works wonderfully with an Order.asc("software.id"), but i cannot make it work with Order.asc("software.name").

Dones anyone have an idea ?
Any help would be greatly appreciated !

Thank you in advance !


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 11:29 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
try

Code:
Criteria criteria = session.createCriteria(
DBSoftwareVersion.class()).createCriteria("software").addOrder(Order.asc("name"));


_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 5:04 am 
Newbie

Joined: Fri Dec 16, 2005 9:51 am
Posts: 3
Thanks for this suggestion kochcp.
Unfortunatly, it causes another error : "subcriteria cannot be ordered".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 10:03 am 
Newbie

Joined: Fri Dec 16, 2005 9:51 am
Posts: 3
After a few more research, it simply seems to be impossible.
The only sorting keys available are the fields of the DBSoftwareVersion's table.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 10:15 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
in your mapping type of DbSoftware, you should probably declare what type (Integer, Long, String, etc) the property 'name' should be. this might make it able to be ordered upon

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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