Hello,
we have a special use-case where we need to sort by database field with a variable sort order. Additonally, and importantly we display these task objects in pages, thus we use limit() and offset() to retrieve only a certain subset of rows.
The application uses QueryDSL 3.3.1 with JPA under WebSphere Application Server 8.0.0.8 (with OpenJPA) and Oracle 11g as underlying database.
Assume the following setup:
- We have a Task object, that contains a state field with the following elements 'V', 'N', 'G' and null.
- We need to sort the Task objects in the following way:
OTHERS first
followed by N
followed by V
followed by G
That means we can't simply use a standary orderBy(task.state.desc()). We therefore implemented a special case structure and do our list of tasks the following way:
final Expression<String> state
= task.state.when("N").then("1")
.when("V").then("2")
.when("G").then("3")
.otherwise("0")
.as("vehicleState");
final StringPath asVehicleState = new StringPath("vehicleState");
final List<Tuple> dbResult = jpaQuery.orderBy(asVehicleState.asc()).offset(0).limit(18).list(task, vehicleState);
This however leads to the following error:
Missing IN or OUT parameter at index:: 4 {prepstmnt 442344100
SELECT * FROM (SELECT t0.PSF_ID AS c0, CASE WHEN t2.VTR_MOBILIENZUSTAND = ? THEN
? WHEN t2.VTR_MOBILIENZUSTAND = ? THEN ? WHEN t2.VTR_MOBILIENZUSTAND = ? THEN ?
ELSE ? END AS vehicleState FROM MAKS.MAKS_POSTFACH t0, MAKS.MAKS_GENEHMIGUNG t1,
MAKS.MAKS_VERTRAG t2 WHERE (t0.PSF_GEN_ID IS NOT NULL AND
t0.PSF_WV_DATUM_AKTUELL <= ? AND t0.PSF_GESCHAEFTPROZESS = ?) AND
t0.PSF_GEN_ID = t1.GEN_ID AND t1.GEN_VTR_ID = t2.VTR_ID ORDER BY vehicleState
ASC, t0.PSF_ID ASC) WHERE ROWNUM <= ? [params=(Timestamp) 2014-04-29
08:13:58.041, (int) 2, (long) 18]}
I've configured JPA to display the parameters given and there are only three parameters given (a timestamp, and integer and a long value).
If I remove the offset and limit (which is out of question, as the table contains hundred thousands of tasks), the query works as expected.
Can somebody please help to figure out what we are doing wrong here or if this might be a bug.
Thank you very much
Heiko