You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/03/28 07:01:52 UTC

[GitHub] [incubator-shardingsphere] kagowu opened a new issue #2122: mybatis 多个参数的insert报错

kagowu opened a new issue #2122: mybatis 多个参数的insert报错
URL: https://github.com/apache/incubator-shardingsphere/issues/2122
 
 
   ## Bug Report
   
   ### 1.版本?
   		<dependency>
   			<groupId>io.shardingsphere</groupId>
   			<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
   			<version>3.1.0</version>
   		</dependency>
   
   mysql-connect-java 5.1.41
   mybatis 3.4.0
   
   ###2. 现象
   我使用的是mybatis 
   数据库是 mysql 
   mybatis的java mapper代码:
   int saveSyncPropertys(@Param("propertys") List<Property> propertys,@Param("updatedTime") Date updatedTime);
   
   mybatis的xml 配置文件(此处省略了其他字段):
   <insert id="saveSyncPropertys">
           insert into ms_property(companyUuid,createdTime) VALUES
           <foreach collection="propertys" item="obj" index="index" separator=",">
               (#{obj.companyUuid},
               ,#{updatedTime})
           </foreach>
           ON DUPLICATE KEY UPDATE
           updatedTime=**#{updatedTime},**
       </insert>
   ### 报错
   Caused by: java.sql.SQLException: No value specified for parameter 149
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
   	at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2211)
   	at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2191)
   	at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2121)
   	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1162)
   	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
   	at io.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:63)
   	at io.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:59)
   	at io.shardingsphere.core.executor.sql.execute.SQLExecuteCallback.execute0(SQLExecuteCallback.java:72)
   	at io.shardingsphere.core.executor.sql.execute.SQLExecuteCallback.execute(SQLExecuteCallback.java:61)
   	at io.shardingsphere.core.executor.ShardingExecuteEngine.syncGroupExecute(ShardingExecuteEngine.java:175)
   	at io.shardingsphere.core.executor.ShardingExecuteEngine.groupExecute(ShardingExecuteEngine.java:152)
   	at io.shardingsphere.core.executor.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:71)
   	at io.shardingsphere.core.executor.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:54)
   	at io.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor.executeCallback(AbstractStatementExecutor.java:114)
   	at io.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor.execute(PreparedStatementExecutor.java:148)
   	at io.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:137)
   	at io.opentracing.contrib.jdbc.TracingPreparedStatement.execute(TracingPreparedStatement.java:177)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
   ### 换种写法
   <insert id="saveSyncPropertys">
           insert into ms_property(companyUuid,createdTime) VALUES
           <foreach collection="propertys" item="obj" index="index" separator=",">
               (#{obj.companyUuid},
               ,#{updatedTime})
           </foreach>
           ON DUPLICATE KEY UPDATE
           updatedTime=**CURRENT_DATE**
       </insert>
   
   就没有问题了。
   
   
   所以关键是最后这个@Param("updatedTime") 莫名其妙丢失了。
   
   检查了底层的方法
   com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2211)
   
   batchedParameterStrings.length=149 
   但是第149个元素是null:
   batchedParameterStrings[148]=null
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services