-->
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: Order based on another table
PostPosted: Wed Apr 01, 2015 5:40 pm 
Newbie

Joined: Wed Apr 01, 2015 5:31 pm
Posts: 1
I have figured out the sql query I want, but now I need to convert it so hibernate performs it.

My desired sql query is the following:

select * from table1 as x where a=1 and b=2 order by (select sum(d+e+f) from table2 where a=x.a and b=x.b and c=x.c) asc

Creating the outer select statement is no problem, but when I create the order it seems to be trying to translate the properties to column names based on table1 when the properties belong to table2. I am not sure how to resolve this.

I have a hack where I extend order and return "select sum(d+e+f) from table2 where a=this_.a and b=this_.b and c=this_.c)" from the function toSqlString. This of course bypasses the hibernate property mappings and I don't know how safe it is to refer to "this_" directly like that. There has to be a better way to do this.


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.