-->
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.  [ 1 post ] 
Author Message
 Post subject: The problem using ORDER BY and expression (CASE WHEN THEN )
PostPosted: Thu Feb 04, 2010 8:48 am 
Newbie

Joined: Thu Feb 04, 2010 8:30 am
Posts: 1
Hi

Could you help me figure out what I've made wrong.. I am reworking the using HQL to Criteria
I have query that worked fine by using HQL

Code:
"SELECT * from nurses order by (CASE type  WHEN 'doctor' THEN 'arts' WHEN  'nurse' THEN 'zuster' ELSE 'Zzz' END) "



but when I try to something like that by criteria it doesn't work ...one of the attempt

Code:
hsession.createCriteria(Nurses.class).criteria.setProjection(Projections.sqlProjection("(CASE type  WHEN 'doctor' THEN 'arts' WHEN  'nurse' THEN 'zuster' ELSE 'Zzz' END) as type_", new String[] { "type_" }, new Type[] { Hibernate.STRING })).addOrder(Order.asc("type_")).list()


it's thrown me the exception

org.hibernate.QueryException: could not resolve property: type_ of: ....

if I use the code like that
Code:
hsession.createCriteria(Nurses.class).addOrder(Order.asc("(CASE type  WHEN 'doctor' THEN 'arts' WHEN  'nurse' THEN 'zuster' ELSE 'Zzz' END)")).list()


i have org.hibernate.QueryException: could not resolve property: (CASE type WHEN 'doctor' THEN 'arts' WHEN 'nurse' THEN 'zuster' ELSE 'Zzz' END) of:


P.S. I use Hibernate-Version: 3.2.1.ga
thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.