MyBatis 3.x error using <foreach ... />

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

MyBatis 3.x error using <foreach ... />

el_mikema
Hello,

Trying to do the following scenario using a DB2 driver, and getting the error at the end.  Is the syntax correct ?

*** >>> Java code snippet  <<<***
       List<String> domainList = new ArrayList<String>(3);
       domainList.add(new String("IDR_EVENT_TOPIC"));
       domainList.add(new String("IDR_EVENT_LANGUAGE"));
       domainList.add(new String("IDR_EVENT_BRAND"));
       
         Iterator<String> iterator1 = domainList.iterator();
         while ( iterator1.hasNext() ){
             System.out.println( iterator1.next() );
         }
       List<Domain> domainTypes = eventService.getDomain(domainList);

*** >>> XML configuration snippet  <<<***
  SELECT
  dt.ett_domain_typeid as dt_typeid,
  dom.ett_desc2 as dom_ett_key_cd2_desc
  FROM ett_domain_type as dt,
  ett_domain dom
  WHERE dt.ett_domain in  
  <foreach item="item" index="index" collection="list"
  open="(" separator="," close=")">
  #{item}
  </foreach>               
  and dom.ett_domain = dt.ett_domain
  and dom.ett_active=1  

*** >>> Above example worked prior to including <foreach ... /> stmt as follows:
    Where dt.ett domain in ('IDR_EVENT_TOPIC','IDR_EVENT_LANGUAGE','IDR_EVENT_BRAND')

*** >>> Snippet of Error <<< ***
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.53.70] Unrecognized JDBC type: 1111. ERRORCODE=-4228, SQLSTATE=null
        at com.ibm.db2.jcc.b.bd.a(bd.java:660)
        at com.ibm.db2.jcc.b.bd.a(bd.java:60)
        at com.ibm.db2.jcc.b.bd.a(bd.java:103)
        at com.ibm.db2.jcc.b.hb.i(hb.java:1282)
        at com.ibm.db2.jcc.b.gm.b(gm.java:656)
        at com.ibm.db2.jcc.b.gm.setNull(gm.java:628)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
        at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:15)
        at org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:73)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:61)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:43)
        at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:56)
        at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:40)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:233)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:112)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:72)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:75)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:615)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
        ... 30 more




Reply | Threaded
Open this post in threaded view
|

Re: MyBatis 3.x error using <foreach ... />

Clinton Begin
Administrator
Try specifying the jdbc type.  It's probably trying to set a null
value, which requires the jdbc type.


On 2011-03-23, el_mikema <[hidden email]> wrote:

> Hello,
>
> Trying to do the following scenario using a DB2 driver, and getting the
> error at the end.  Is the syntax correct ?
>
> *** >>> Java code snippet  <<<***
>        List domainList = new ArrayList(3);
>        domainList.add(new String("IDR_EVENT_TOPIC"));
>        domainList.add(new String("IDR_EVENT_LANGUAGE"));
>        domainList.add(new String("IDR_EVENT_BRAND"));
>
>          Iterator iterator1 = domainList.iterator();
>          while ( iterator1.hasNext() ){
>              System.out.println( iterator1.next() );
>          }
>        List domainTypes = eventService.getDomain(domainList);
>
> *** >>> XML configuration snippet  <<<***
>   SELECT
>   dt.ett_domain_typeid as dt_typeid,
>   dom.ett_desc2 as dom_ett_key_cd2_desc
>   FROM ett_domain_type as dt,
>   ett_domain dom
>   WHERE dt.ett_domain in
>  
>   #{item}
>  
>   and dom.ett_domain = dt.ett_domain
>   and dom.ett_active=1
>
> *** >>> Above example worked prior to including  stmt as follows:
>     Where dt.ett domain in
> ('IDR_EVENT_TOPIC','IDR_EVENT_LANGUAGE','IDR_EVENT_BRAND')
>
> *** >>> Snippet of Error <<< ***
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.53.70]
> Unrecognized JDBC type: 1111. ERRORCODE=-4228, SQLSTATE=null
> at com.ibm.db2.jcc.b.bd.a(bd.java:660)
> at com.ibm.db2.jcc.b.bd.a(bd.java:60)
> at com.ibm.db2.jcc.b.bd.a(bd.java:103)
> at com.ibm.db2.jcc.b.hb.i(hb.java:1282)
> at com.ibm.db2.jcc.b.gm.b(gm.java:656)
> at com.ibm.db2.jcc.b.gm.setNull(gm.java:628)
> at
> org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
> at
> org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
> at
> org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:15)
> at
> org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:73)
> at
> org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:61)
> at
> org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:43)
> at
> org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:56)
> at
> org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:40)
> at
> org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:233)
> at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:112)
> at
> org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:72)
> at
> org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:75)
> at
> org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:615)
> at
> org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
> ... 30 more
>
>
>
>
>
>
> --
> View this message in context:
> http://mybatis-user.963551.n3.nabble.com/MyBatis-3-x-error-using-foreach-tp2719558p2719558.html
> Sent from the mybatis-user mailing list archive at Nabble.com.
>

--
Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: MyBatis 3.x error using <foreach ... />

satte0528
Hi, Clinton,

   I have the same problem even i have set the jdbc type still getting the same problem.. Please find my mapper class.. its the problem only on update query..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="nj.lwd.copywork.web.persistence.newJobEntry.RequesterMapper">
   
    <resultMap id="result" type="requesterBean">
        <result property="idnRequestor" column="IDN_REQUESTOR"  />
        <result property="nmeRequestorLast" column="NME_REQUESTOR_LAST"/>
        <result property="nmeRequestorFirst" column="NME_REQUESTOR_FIRST"/>
        <result property="nmeRequestorMinit" column="NME_REQUESTOR_MINIT"/>
        <result property="nmeSuffix" column="NME_SUFFIX"/>
        <result property="nmeDegree" column="NME_DEGREE"/>
        <result property="nmeTitle" column="NME_TITLE"/>
        <result property="cdeStatusRequestor" column="CDE_STATUS_REQUESTOR"/>
        <result property="nmeRequestorFirm" column="NME_REQUESTOR_FIRM"/>
        <result property="adrStreet1" column="ADR_STREET1"/>
        <result property="adrStreet2" column="ADR_STREET2"/>
        <result property="adrCity" column="ADR_CITY"/>
        <result property="adrState" column="ADR_STATE"/>
        <result property="adrZip5" column="ADR_ZIP5"/>
        <result property="adrZip4" column="ADR_ZIP4"/>
        <result property="adrCountry" column="ADR_COUNTRY"/>
        <result property="adrPhone1" column="ADR_PHONE1" javaType="Integer" jdbcType="INTEGER" />
        <result property="adrPhone2" column="ADR_PHONE2" javaType="Integer" jdbcType="INTEGER" />
        <result property="adrPhone3" column="ADR_PHONE3" javaType="Integer" jdbcType="INTEGER" />
        <result property="cdeStatusDesc" column="DESC_STATUS_REQUESTOR"/>
        <result property="amtBalance" column="AMT_BALANCE"/>
        <result property="createdOn" column="DTE_ACCT_OPENED"/>
        <result property="lastUpdatedBy" column="UPDATE_BY"/>
        <result property="lastUpdatedOn" column="UPDATE_DATE"/>
        <result property="cdeComment" column="COMMENTS"/>
        <result property="emailAddress" column="EMAIL"/>
        <result property="phoneExt" column="PHONE_EXT" javaType="Integer" jdbcType="INTEGER" />
    </resultMap>

   
    <update id="updateRequesterDetails" parameterType="requesterBean" >
        UPDATE CW_REQUESTORS
        SET
            NME_REQUESTOR_LAST = #{nmeRequestorLast,jdbcType=VARCHAR},           
            NME_REQUESTOR_FIRST = #{nmeRequestorFirst,jdbcType=VARCHAR},
            NME_REQUESTOR_FIRM = #{nmeRequestorFirm,jdbcType=VARCHAR},
            NME_REQUESTOR_MINIT = #{nmeRequestorMinit,jdbcType=VARCHAR},
            NME_SUFFIX = #{nmeSuffix,jdbcType=VARCHAR},
            ADR_STREET1 = #{adrStreet1,jdbcType=VARCHAR},
            ADR_STREET2 = #{adrStreet2,jdbcType=VARCHAR},
            ADR_CITY = #{adrCity,jdbcType=VARCHAR},
            ADR_STATE = #{adrState,jdbcType=VARCHAR},
            ADR_COUNTRY = #{adrCountry,jdbcType=VARCHAR},
            EMAIL = #{emailAddress,jdbcType=VARCHAR},
            UPDATE_BY = #{lastUpdatedBy,jdbcType=VARCHAR},
        WHERE IDN_REQUESTOR = #{idnRequestor}   
      </update>
     
<insert id='insertRequesterDetails' parameterType='requesterBean' >
       INSERT INTO CW_REQUESTORS(IDN_REQUESTOR,
                                NME_REQUESTOR_LAST,
                                NME_REQUESTOR_FIRST,                               
                                NME_REQUESTOR_MINIT,                               
                                NME_SUFFIX,                               
                                ADR_STREET1,
                                ADR_STREET2,
                                ADR_CITY,
                                ADR_STATE,
                                ADR_ZIP5,   
                                ADR_ZIP4,
                                ADR_COUNTRY,
                                ADR_PHONE1,                           
                                ADR_PHONE2,                           
                                ADR_PHONE3,
                                NME_REQUESTOR_FIRM,   
                                EMAIL,                       
                                PHONE_EXT,                       
                                AMT_BALANCE,
                                CDE_STATUS_REQUESTOR,                           
                                DTE_ACCT_OPENED,
                                UPDATE_BY
                               
        )
        VALUES(    #{idnRequestor},
                #{nmeRequestorLast},
                #{nmeRequestorFirst},                               
                #{nmeRequestorMinit},                               
                #{nmeSuffix},                           
                #{adrStreet1},
                #{adrStreet2},
                #{adrCity},   
                #{adrState},
                #{adrZip5},   
                #{adrZip4},
                #{adrCountry},
                #{adrPhone1},       
                #{adrPhone2},       
                #{adrPhone3},
                #{nmeRequestorFirm},
                #{emailAddress},       
                #{phoneExt},       
                #{amtBalance},
                #{cdeStatusRequestor},
                #{createdOn},
                #{lastUpdatedBy}
             )
      </insert>
     
     
 
</mapper>

Could you please help me where i am wrong..

Thanks,
Srini


On Friday, March 25, 2011 9:53:50 AM UTC-4, Clinton Begin wrote:
Try specifying the jdbc type.  It's probably trying to set a null
value, which requires the jdbc type.


On 2011-03-23, el_mikema <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="UTkfdCY8U58J">el_m...@...> wrote:


> Hello,
>
> Trying to do the following scenario using a DB2 driver, and getting the
> error at the end.  Is the syntax correct ?
>
> *** >>> Java code snippet  <<<***                                                
>        List domainList = new ArrayList(3);
>        domainList.add(new String("IDR_EVENT_TOPIC"));
>        domainList.add(new String("IDR_EVENT_LANGUAGE"));
>        domainList.add(new String("IDR_EVENT_BRAND"));        
>
>          Iterator iterator1 = domainList.iterator();
>          while ( iterator1.hasNext() ){
>              System.out.println( iterator1.next() );
>          }                        
>        List domainTypes = eventService.getDomain(domainList);
>
> *** >>> XML configuration snippet  <<<***
>   SELECT
>           dt.ett_domain_typeid as dt_typeid,
>           dom.ett_desc2 as dom_ett_key_cd2_desc
>   FROM ett_domain_type as dt,
>           ett_domain dom
>   WHERE dt.ett_domain in
>           
>                   #{item}
>                           
>   and dom.ett_domain = dt.ett_domain
>   and dom.ett_active=1        
>
> *** >>> Above example worked prior to including  stmt as follows:
>     Where dt.ett domain in
> ('IDR_EVENT_TOPIC','IDR_EVENT_LANGUAGE','IDR_EVENT_BRAND')
>
> *** >>> Snippet of Error <<< ***
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: com.ibm.db2.jcc.b.SqlException: [jcc][10271][10295][3.53.70]
> Unrecognized JDBC type: 1111. ERRORCODE=-4228, SQLSTATE=null
>         at com.ibm.db2.jcc.b.bd.a(bd.java:660)
>         at com.ibm.db2.jcc.b.bd.a(bd.java:60)
>         at com.ibm.db2.jcc.b.bd.a(bd.java:103)
>         at com.ibm.db2.jcc.b.hb.i(hb.java:1282)
>         at com.ibm.db2.jcc.b.gm.b(gm.java:656)
>         at com.ibm.db2.jcc.b.gm.setNull(gm.java:628)
>         at
> org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
>         at
> org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
>         at
> org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:15)
>         at
> org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:73)
>         at
> org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:61)
>         at
> org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:43)
>         at
> org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:56)
>         at
> org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:40)
>         at
> org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:233)
>         at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:112)
>         at
> org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:72)
>         at
> org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:75)
>         at
> org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:615)
>         at
> org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
>         ... 30 more
>
>
>
>
>
>
> --
> View this message in context:
> http://mybatis-user.963551.n3.nabble.com/MyBatis-3-x-error-using-foreach-tp2719558p2719558.html
> Sent from the mybatis-user mailing list archive at Nabble.com.
>

--

Sent from my mobile device

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: MyBatis 3.x error using <foreach ... />

Rick R
In reply to this post by el_mikema
On Wed, Mar 23, 2011 at 5:02 AM, el_mikema <[hidden email]> wrote:
 
  WHERE dt.ett_domain in

                #{item}

   

Did the foreach get stripped out somehow? I don't see it above?

I take it you have something list this in your real code?

WHERE dt.ett_domain in
<foreach item="item" open="("  collection="domainList" separator="," close=")">
  #{item}
</foreach>

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.