Announcement Announcement Module
Collapse
No announcement yet.
Weird exception for Spring & iBatis database insert Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Weird exception for Spring & iBatis database insert

    Having using Spring & iBatis for several months and upgraded iBatis from 1.x to 2.0, every thing seems fine, but I saw weird exception thrown regarding insert 7 or 8 inline params into MySQL by iBatis, here is the process:

    1. a straightforward update SQL for iBatis

    <update id="createUser" parameterClass="com.somecom.model.User">
    INSERT INTO
    ds_user ( USERID, USERNAME, PASSWORD, SCREENNAME, STATUSID, TYPEID, ZONEID, EMAIL)
    VALUES (#userid#, #username#, #password#, #screenname#, #statusid#, #typeid#, #zoneid#, #email#)
    </update>


    2. calling from a DAO using Spring SqlMapClientTemplate

    getSqlMapClientTemplate().update("createUser", aUser);

    3. it will throw exception complain that the primary key USERID is null while it is not.

    4. this happened only for 7 or 8 inline params, if useing less than 6 or more than 9 inline parameters, it worked fine. For example this will work just fine:

    <update id="createUser" parameterClass="com.somecom.model.User">
    INSERT INTO
    User_table (USERID, USERNAME, PASSWORD, SCREENNAME, STATUSID, TYPEID, ZONEID, LASTLOGIN, EMAIL)
    VALUES (#userid#, #username#, #password#, #screenname#, #statusid#, #typeid#, #zoneid#, #lastlogin#, #email#)
    </update>

    5. I guess this is something regarding spring’s code since I have upgraded iBatis from 1.x to 2.0, the exception still there

    Here is more exception details, sorry for posting such long post.


    [junit] DEBUG [main] ConnectionLogProxy.<init>(24) | {conn-100003} Connection
    [junit] DEBUG [main] PreparedStatementLogProxy.invoke(30) |{pstm-100004} PreparedStatement: INSERT INTO ds_user (USERID, USERNAME, PASSWOR
    D, SCREENNAME, STATUSID, TYPEID, ZONEID, EMAIL) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
    [junit] [ape] DEBUG [main] PreparedStatementLogProxy.invoke(31) | {pstm-100004} Parameters:
    [10, a3, bHVieDM1, a3, 0, 0, 1, [email protected]]


    [junit] ------------- Standard Output ---------------
    [junit] org.somecom.model.User@1ce784b[
    [junit] userid=10
    [junit] username=a3
    [junit] password=bHVieDM1
    [junit] screenname=a3
    [junit] statusid=0
    [junit] typeid=0
    [junit] email=[email protected]
    [junit] createdate=1100018192984
    [junit] zoneid=1
    [junit] ]
    [junit] ------------- ---------------- ---------------

    [junit] --- Cause: java.sql.SQLException: Column 'USERID' cannot be null
    [junit] Caused by: java.sql.SQLException: Column 'USERID' cannot be null
    [junit] at com.ibatis.sqlmap.engine.mapping.statement.General Statement.execut
    eUpdate(GeneralStatement.java:72)
    [junit] at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelega te.update(SqlMap
    ExecutorDelegate.java:279)
    [junit] at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.up date(SqlMapSessi
    onImpl.java:61)
    [junit] at org.springframework.orm.ibatis.SqlMapClientTemplat e$11.doInSqlMapC
    lient(SqlMapClientTemplate.java:282)

    [junit] at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMap
    ClientTemplate.java:140)
    [junit] at org.springframework.orm.ibatis.SqlMapClientTemplat e.update(SqlMapC
    lientTemplate.java:280)

    [junit] Caused by: java.sql.SQLException: Column 'USERID' cannot be null
    [junit] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2551)
    [junit] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:14 43)
    [junit] at com.mysql.jdbc.ServerPreparedStatement.serverExecu te(ServerPrepare
    dStatement.java:1239)
    [junit] at com.mysql.jdbc.ServerPreparedStatement.executeInte rnal(ServerPrepa
    redStatement.java:903)
    [junit] at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.j
    ava:1871)
    [junit] at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.j
    ava:1796)
    [junit] at com.mysql.jdbc.PreparedStatement.executeUpdate(Pre paredStatement.j
    ava:1658)

    [junit] at com.ibatis.common.jdbc.logging.PreparedStatementLo gProxy.invoke(Pr
    eparedStatementLogProxy.java:39)
    [junit] at $Proxy1.executeUpdate(Unknown Source)
    [junit] at com.ibatis.sqlmap.engine.execution.SqlExecutor.exe cuteUpdate(SqlEx
    ecutor.java:58)
    [junit] at com.ibatis.sqlmap.engine.mapping.statement.General Statement.sqlExe
    cuteUpdate(GeneralStatement.java:169)
    [junit] at com.ibatis.sqlmap.engine.mapping.statement.General Statement.execut
    eUpdate(GeneralStatement.java:59)
    [junit] ... 21 more

    [junit] Caused by:
    [junit] java.sql.SQLException: Column 'USERID' cannot be null

    [junit] at com.ibatis.common.jdbc.logging.PreparedStatementLo gProxy.invoke(Pr
    eparedStatementLogProxy.java:39)
    [junit] at $Proxy1.executeUpdate(Unknown Source)
    [junit] at com.ibatis.sqlmap.engine.execution.SqlExecutor.exe cuteUpdate(SqlEx
    ecutor.java:58)
    [junit] at com.ibatis.sqlmap.engine.mapping.statement.General Statement.sqlExe
    cuteUpdate(GeneralStatement.java:169)
    [junit] at com.ibatis.sqlmap.engine.mapping.statement.General Statement.execut
    eUpdate(GeneralStatement.java:59)
    [junit] at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelega te.update(SqlMap
    ExecutorDelegate.java:279)
    [junit] at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.up date(SqlMapSessi
    onImpl.java:61)
    [junit] at org.springframework.orm.ibatis.SqlMapClientTemplat e$11.doInSqlMapC
    lient(SqlMapClientTemplate.java:282)
    [junit] at org.springframework.orm.ibatis.SqlMapClientTemplat e.execute(SqlMap
    ClientTemplate.java:140)
    [junit] at org.springframework.orm.ibatis.SqlMapClientTemplat e.update(SqlMapC
    lientTemplate.java:280)

    thanks for help!

    bill

  • #2
    That's weird... Spring doesn't do anything special in terms of iBATIS SQL Maps operations; it just delegates them to the SqlMapClient. You could easily track this down: Set up a plain SqlMapClient and invoke the same operation. I bet you'll encounter the problem there too, provided that the circumstances are the same.

    I recommend to ask on the iBATIS forum, as this is very likely to be an issue with your mapped statement definitions rather than with Spring's iBATIS integration.

    Juergen

    Comment


    • #3
      Thanks Juergen

      I will do more work on iBatis side to see where could be the problem.

      /bill

      Comment

      Working...
      X