Hello! I'm trying to emulate this query using Criteria and Projections, but I can't do it:
Code:
SELECT rese_pos_id
FROM (SELECT DISTINCT rese_pos_id, rese_pos_ord
FROM researcher_position
ORDER BY rese_pos_ord) idsOrd;
I achieved to build the "subquery" :
Code:
return (Collection<Integer>) getSession().createCriteria(ResearcherPosition.class)
.setProjection(Projections.distinct(
Projections.projectionList()
.add(Projections.property("researcherPositionPK.positionID"))
.add(Projections.property("order"))))
.addOrder(Order.asc("order"))
.list();
but I don't know the way to "project" the final result over the column "rese_pos_id". I need the other column (
rese_pos_ord) to order the elements into the column
rese_pos_id, so it's neccesary to put it into the SELECT. The "subquery" works alone, retrieving this data:
Code:
rese_pos_id | rese_pos_ord
----------------------------------
5 | 1
6 | 2
1 | 3
but, how can I project in the final result only the column
rese_pos_id ? I was thinking about a DetachedCriteria, but I don't know how to build a Criteria about the result of the detached one.
Thanks