MyBatis Issue with IN Condition <foreach with List dentro de un mapa
Tengo que construir una condición IN usando MyBatis donde tengo que pasar una lista dePARENT_VALUES
para obtener basado en el siguiente bucle foreach ....
Lo intenté pero no pude resolver esto. No estoy seguro si
Los valores pasados son:
Map input = new HashMap();
input.put("somedata");
List<String> inConditionList = new ArrayList<String>();
inConditionList.add("P1");
inConditionList.add("P2");
input.put(inConditionList);
sqlSessionTemplate.selectList("getNameAgeDetails", input);
SQL requerido:
SELECT P.NAME, P.AGE
FROM PERSON_DETAILS P
WHERE SOMECOLUMN is NULL AND DATA IN
(SELECT DATA FROM PARENT_TABLE WHERE PARENT_VALUE IN ("P1, "P2"))
ORDER BY P.NAME
FETCH FIRST 10 ROW ONLY
MyBatis Mapper SQL:
<select id="getNameAgeDetails" parameterType="map" resultMap="someResultMap">
<![CDATA[
SELECT P.NAME, P.AGE
FROM PERSON_DETAILS P
WHERE
SOMECOLUMN is NULL
AND DATA IN
(SELECT DATA
FROM PARENT_TABLE
WHERE PARENT_VALUE IN
<FOREACH item="item" index="index" collection="list" separator="," open="(" close=")">
${item}
</FOREACH>
)
ORDER BY P.NAME
FETCH
FIRST 10 ROW ONLY
]]>
</select>
A continuación se muestra el error que recibo cuando intento ejecutar mis TestCases de unidad:
### The error occurred while setting parameters
### SQL: SELECT P.NAME, P.AGE
FROM PERSON_DETAILS P
WHERE
SOMECOLUMN is NULL
AND DATA IN
(SELECT DATA
FROM PARENT_TABLE
WHERE PARENT_VALUE IN <FOREACH item="item" index="index" collection="list" separator="," open="(" close=")"> ? </FOREACH>
### Cause: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=PARENT_VALUE IN
<foreach it;TION
WHERE;<space>, DRIVER=3.63.75
; bad SQL grammar []; nested exception is com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=PARENT_VALUE IN