title: How use mybatis to update table field where the type is list
body: <p>table:</p>
  <pre><code>CREATE TABLE IF NOT EXISTS `policy` (
      `id`         VARCHAR(32) NOT NULL COMMENT '策略ID',
      `name`       VARCHAR(32) NOT NULL COMMENT '策略名',
      `version`    VARCHAR(11) NOT NULL COMMENT '策略版本',
      `statements` VARCHAR(1024) NOT NULL COMMENT '策略表达式',
      PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC COMMENT='策略';
  </code></pre>
  <p>mybatis config file:</p>
  <pre><code>    &lt;typeHandlers&gt;
          &lt;typeHandler handler=&quot;io.github.ctlove0523.toyiam.server.model.storage.handler.PolicyStatementsHandler&quot;
                       javaType=&quot;List&quot;/&gt;
      &lt;/typeHandlers&gt;
  </code></pre>
  <p>PolicyStatementsHandler:</p>
  <pre><code>public class PolicyStatementsHandler extends BaseTypeHandler&lt;List&lt;PolicyStatement&gt;&gt; {
      @Override
      public void setNonNullParameter(PreparedStatement preparedStatement, int i, List&lt;PolicyStatement&gt; policyStatements, JdbcType jdbcType) throws SQLException {
          preparedStatement.setString(i, JacksonUtil.object2Json(policyStatements));
      }
  
      @Override
      public List&lt;PolicyStatement&gt; getNullableResult(ResultSet resultSet, String s) throws SQLException {
          return JacksonUtil.json2List(resultSet.getString(s), PolicyStatement.class);
      }
  
      @Override
      public List&lt;PolicyStatement&gt; getNullableResult(ResultSet resultSet, int i) throws SQLException {
          return JacksonUtil.json2List(resultSet.getString(i), PolicyStatement.class);
      }
  
      @Override
      public List&lt;PolicyStatement&gt; getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
          return JacksonUtil.json2List(callableStatement.getString(i), PolicyStatement.class);
      }
  }
  </code></pre>
  <p>PolicyMapper.xml</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE mapper PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot; &quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;&gt;
  &lt;mapper namespace=&quot;io.github.ctlove0523.toyiam.server.model.storage.mapper.PolicyMapper&quot;&gt;
  
      &lt;resultMap id=&quot;policyResultMap&quot; type=&quot;Policy&quot;&gt;
          &lt;id property=&quot;id&quot; column=&quot;id&quot;/&gt;
          &lt;result property=&quot;name&quot; column=&quot;name&quot;/&gt;
          &lt;result property=&quot;version&quot; column=&quot;version&quot;/&gt;
          &lt;result property=&quot;statements&quot; column=&quot;statements&quot; typeHandler=&quot;io.github.ctlove0523.toyiam.server.model.storage.handler.PolicyStatementsHandler&quot;/&gt;
      &lt;/resultMap&gt;
  
      &lt;insert id=&quot;savePolicy&quot; parameterType=&quot;Policy&quot;&gt;
          INSERT INTO policy(id,name,version,statements)
          VALUE(#{id},#{name},#{version},#{statements})
      &lt;/insert&gt;
  
      &lt;update id=&quot;updateVersionAndStatements&quot;&gt;
          UPDATE policy
          SET statements = #{statements},version = #{version}
          WHERE id = #{id}
      &lt;/update&gt;
  
  &lt;/mapper&gt;
  </code></pre>
  <p>PolicyMapper.java</p>
  <pre><code>public interface PolicyMapper {
  
      void savePolicy(Policy policy);
  
      void updateVersionAndStatements(@Param(&quot;id&quot;) String id, @Param(&quot;version&quot;) String version, @Param(&quot;statements&quot;) List&lt;PolicyStatement&gt; statements);
  }
  </code></pre>
  <p>problem:
  savePolicy method works well but updateVersionAndStatements throw exception: Type java.util.ArrayList not supported type.
  How should i do to fix this problem?
  Error Stack:</p>
  <pre><code>==&gt;  Preparing: UPDATE policy SET statements = ?,version = ? WHERE id = ?
  Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@34a9f817]
  2022-08-06 14:52:15.522 ERROR 11512 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='statements', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Type java.util.ArrayList not supported type] with root cause
  
  java.sql.SQLException: Type java.util.ArrayList not supported type
      at org.mariadb.jdbc.BasePreparedStatement.setInternalObject(BasePreparedStatement.java:1103) ~[mariadb-java-client-3.0.5.jar:na]
      at org.mariadb.jdbc.BasePreparedStatement.setObject(BasePreparedStatement.java:644) ~[mariadb-java-client-3.0.5.jar:na]
      at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setObject(HikariProxyPreparedStatement.java) ~[HikariCP-3.2.0.jar:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
      at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
      at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67) ~[mybatis-3.5.9.jar:3.5.9]
      at com.sun.proxy.$Proxy78.setObject(Unknown Source) ~[na:na]
      at org.apache.ibatis.type.ObjectTypeHandler.setNonNullParameter(ObjectTypeHandler.java:31) ~[mybatis-3.5.9.jar:3.5.9]
      at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:73) ~[mybatis-3.5.9.jar:3.5.9]
      at org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:67) ~[mybatis-3.5.9.jar:3.5.9]
  </code></pre>