MySQL query is as follow
update group_entity set deleted = 1 where entity_id in (select entity_id from entity where entity_row_id in ('1-424g','1-242T') and entity_type='Data');
this query is working in mysql.
my Ibatis query with changes is as follow
<update id="updateData" parameterClass="abc.data.updateDataParameters">
update group_entity set deleted = 1 where entity_id in
<iterate open="(" close=")" conjunction=",">
select entity_id from entity where entity_row_id in
<iterate property="parentIds" open="(" close=")" conjunction=",">
#parentIds[]#
</iterate>
and entity_type = #parentType#
</iterate>
</update>
But Ibatis query is not working getting Error ParameterObject or property was not a Collection, Array or Iterator. Error:
--- Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or property was not a Collection, Array or Iterator.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
Please tell me how do i use select statement in iterate like <iterate>Select id from table</iterate>
which returning list of id.
My updateDataParameters
class updateDataParameters
{
List<String> parentId;
string parentType;
// with getter and setter and receptive constructor
}
First iterate element is not necessary. Your request should be:
<update id="updateData" parameterClass="abc.data.updateDataParameters">
update group_entity set deleted = 1 where entity_id in (
select entity_id from entity where entity_row_id in
<iterate property="parentId" open="(" close=")" conjunction=",">
#parentId[]#
</iterate>
) and entity_type = #parentType#
</update>
There is also a typo mistake: parentIds should be parentId to match class attribute.