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.
|