I am building a report from information received from a muti-select form element in a jsp page.
In my repository class I am getting an array of objects from that element. I need to call the getId function for each one of these objects and send those ids to the NamedQuery.
Here is a code example to help explain. I know how to handle a single object but with an array of objects I get lost at the .setParameter(1, employees[].getId()) part.
public List<RequestByRequester> getFormInformation(
Employee[] employees)
throws NoDataFoundException {
List<RequestByRequester> resultList = getEm().createNamedQuery(
"requestByRequestor.getRequestsByRequesters", RequestByRequester.class)
.setParameter(1, employees[].getId())
.getResultList();
return resultList;
}
By request the query:
SELECT EMP.EMPL_FIRST_NAME || ' ' || EMP.EMPL_LAST_NAME REQUESTER,
R.RQST_ID RQST_ID,
R.TITLE TITLE,
R.DESCRIPTION DESCR,
DECODE(R.RESOLUTION_DATE, NULL, 'Open', 'Closed') STAT
FROM TARTS.REQUESTS R, SYS_EMPLOYEES EMP
WHERE R.EMPL_ID_REQUESTED_BY = EMP.EMPL_ID
AND EMP.EMPL_ID IN (?)
ORDER BY 1, 5 DESC, 2
I tried calling Madame Mystique to get help with finding out what your query actually was, but no luck, so I’m just going to go for it…
Your named query should look something like this:
then get your ids into a list
then use this to specify it in your query