Example of IN clause

1,498 views
Skip to first unread message

jluisromero

unread,
Jun 29, 2010, 3:14:09 PM6/29/10
to mybatis-user
I'm using mybatis with a new project. But I have a problem with IN
clause.

Now I have this:

xml for IN clause:
<select id="cuentaContactosEnEnvios"
resultType="ContactosEnEnvios">
SELECT ref_envios as envio, sum(if(c.status=0,1,0) as nuevos,
sum(if(c.status=1,1,0) as enProceso,
sum(if(c.status=2,1,0) as procesados,
sum(if(c.status &lt; 3,1,0) as total FROM Contactos
WHERE ref_envios IN
<foreach collection="arraylist">
#{}#
</foreach>
</select>

method for use IN clause
public List cuentaContactosEnEnvio(ArrayList envios) throws
IOException{
List contactos;
this.ir = new IbatisResources();
this.ir.openSessionFactory();
this.contactMapper =
ir.session.getMapper(ContactMapper.class);
contactos = contactMapper.cuentaContactosEnEnvio(envios);
this.ir.closeSessionFactory();
return contactos;
}

method in interface
public List<ContactosEnEnvios> cuentaContactosEnEnvio(ArrayList
envios);

I have this exception:
Exception in thread "main" java.lang.IllegalArgumentException: Mapped
Statements collection does not contain value for
paynini.ibatis.data.ContactMapper.cuentaContactosEnEnvio
at org.apache.ibatis.session.Configuration
$StrictMap.get(Configuration.java:462)
at
org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:
349)
at
org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:
137)
at
org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:46)
at
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:34)
at $Proxy2.cuentaContactosEnEnvio(Unknown Source)
at
paynini.ibatis.IbatisContact.cuentaContactosEnEnvio(IbatisContact.java:
52)

Please, say me the error or give me an full example of IN clause with
xml. I'm tired of this one. Three days trying solve it.

Jose Luis

Philippe Bajoit

unread,
Jun 30, 2010, 2:12:32 AM6/30/10
to mybatis-user
There is an example of a Map with IN clause:
<select id="countRemainingDM" resultType="Integer">
SELECT COUNT(*)
FROM LIU
WHERE LIDNUM IN
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>

I'm not sure that the index is required

The Java part is like this:
public int getCountFormDM(List<Integer> references) {
return (Integer) sqlSession.selectOne("countRemainingDM",
references);
}

Rgds
Philippe

Jose Luis

unread,
Jun 30, 2010, 1:58:55 PM6/30/10
to mybatis-user


On 30 jun, 01:12, Philippe Bajoit <philippe.baj...@gmail.com> wrote:
> There is an example of a Map with IN clause:
>         <select id="countRemainingDM" resultType="Integer">
>         SELECT COUNT(*)
>                 FROM LIU
>                 WHERE LIDNUM IN
>                 <foreach item="item" index="index" collection="list"
>                         open="(" separator="," close=")">
>                         #{item}
>                 </foreach>
>         </select>
>
> I'm not sure that the index is required
>
> The Java part is like this:
>         public int getCountFormDM(List<Integer> references) {
>                 return (Integer) sqlSession.selectOne("countRemainingDM",
>                                 references);
>         }
>
> Rgds
> Philippe
>


Philippe

Your comment was good!. Now my select with IN clause is working fine.
I had an error in query too; (()

Jose Luis
Reply all
Reply to author
Forward
0 new messages