2014-10-30 94 views
0

MySQL查询是遵循如何在IBATIS迭代中使用select语句?

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'); 

此查询工作在MySQL。

我ibatis的查询与修改是遵循

<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> 

但是ibatis的查询工作不得到错误ParameterObject或财产是不是一个集合,数组或迭代器。 错误:

--- 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: 

请告诉我,我如何使用select语句在迭代像<iterate>Select id from table</iterate>其返回的ID列表。

我updateDataParameters

class updateDataParameters 
{ 
List<String> parentId; 
string parentType; 
// with getter and setter and receptive constructor 
} 

回答

1

首先迭代元素是没有必要的。 您的要求应该是:

<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> 

还有一个错字错:parentIds应的parentId匹配类属性。

+0

谢谢兄弟你的权利:) – Addy 2014-10-30 09:21:20