<p dir="auto">proxy commit id : <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/apache/shardingsphere/commit/51ec973a056b3414f80b2d207f2236ac184f6a2e/hovercard" href="https://github.com/apache/shardingsphere/commit/51ec973a056b3414f80b2d207f2236ac184f6a2e"><tt>51ec973</tt></a></p>
<p dir="auto">following is the step to reproduce the issue :</p>
<ol dir="auto">
<li>downlod the shardingsphere code and checkout as the corresponding commit version</li>
<li>compile the code and extract proxy distribution</li>
<li>use the following config and then start proxy</li>
</ol>
<p dir="auto">config-encrypt.yaml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="schemaName: encrypt_db

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/encrypt_db?serverTimezone=UTC&amp;useSSL=false
    username: root
    password:  
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 3000
    minPoolSize: 1

rules:
- !ENCRYPT
  encryptors:
    sm4_encryptor:
      type: SM4
      props:
        sm4-key: 123456ab
        sm4-mode: ECB
        sm4-padding: PKCS5Padding
    md5_encryptor:
      type: MD5
  tables:
    sbtest1:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest2:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest3:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest4:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest5:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest6:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest7:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest8:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest9:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest10:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
  queryWithCipherColumn: true"><pre class="notranslate"><code class="notranslate">schemaName: encrypt_db

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/encrypt_db?serverTimezone=UTC&amp;useSSL=false
    username: root
    password:  
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 3000
    minPoolSize: 1

rules:
- !ENCRYPT
  encryptors:
    sm4_encryptor:
      type: SM4
      props:
        sm4-key: 123456ab
        sm4-mode: ECB
        sm4-padding: PKCS5Padding
    md5_encryptor:
      type: MD5
  tables:
    sbtest1:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest2:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest3:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest4:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest5:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest6:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest7:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest8:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest9:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
    sbtest10:
      columns:
        pad:
          cipherColumn: pad
          encryptorName: sm4_encryptor
  queryWithCipherColumn: true
</code></pre></div>
<p dir="auto">server.yaml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rules:
  - !AUTHORITY
    users:
      - root@%:root
      - sharding@:sharding
    provider:
      type: ALL_PRIVILEGES_PERMITTED
#  - !TRANSACTION
#    defaultType: XA
#    providerType: Atomikos
#  - !SQL_PARSER
#    sqlCommentParseEnabled: true
#    sqlStatementCache:
#      initialCapacity: 2000
#      maximumSize: 65535
#      concurrencyLevel: 4
#    parseTreeCache:
#      initialCapacity: 128
#      maximumSize: 1024
#      concurrencyLevel: 4

props:
#  max-connections-size-per-query: 1
#  kernel-executor-size: 16  # Infinite by default.
#  proxy-frontend-flush-threshold: 128  # The default value is 128.
#  proxy-opentracing-enabled: false
#  proxy-hint-enabled: false
#  sql-show: false
#  check-table-metadata-enabled: false
#  show-process-list-enabled: false
#    # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.
#    # The default value is -1, which means set the minimum value for different JDBC drivers.
#  proxy-backend-query-fetch-size: -1
#  check-duplicate-table-enabled: false
#  proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
#    # Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution
#    # if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.
  proxy-backend-executor-suitable: OLTP
#  proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.
#  sql-federation-enabled: false
#    # Available proxy backend driver type: JDBC (default), ExperimentalVertx
#  proxy-backend-driver-type: JDBC"><pre class="notranslate"><code class="notranslate">rules:
  - !AUTHORITY
    users:
      - root@%:root
      - sharding@:sharding
    provider:
      type: ALL_PRIVILEGES_PERMITTED
#  - !TRANSACTION
#    defaultType: XA
#    providerType: Atomikos
#  - !SQL_PARSER
#    sqlCommentParseEnabled: true
#    sqlStatementCache:
#      initialCapacity: 2000
#      maximumSize: 65535
#      concurrencyLevel: 4
#    parseTreeCache:
#      initialCapacity: 128
#      maximumSize: 1024
#      concurrencyLevel: 4

props:
#  max-connections-size-per-query: 1
#  kernel-executor-size: 16  # Infinite by default.
#  proxy-frontend-flush-threshold: 128  # The default value is 128.
#  proxy-opentracing-enabled: false
#  proxy-hint-enabled: false
#  sql-show: false
#  check-table-metadata-enabled: false
#  show-process-list-enabled: false
#    # Proxy backend query fetch size. A larger value may increase the memory usage of ShardingSphere Proxy.
#    # The default value is -1, which means set the minimum value for different JDBC drivers.
#  proxy-backend-query-fetch-size: -1
#  check-duplicate-table-enabled: false
#  proxy-frontend-executor-size: 0 # Proxy frontend executor size. The default value is 0, which means let Netty decide.
#    # Available options of proxy backend executor suitable: OLAP(default), OLTP. The OLTP option may reduce time cost of writing packets to client, but it may increase the latency of SQL execution
#    # if client connections are more than proxy-frontend-netty-executor-size, especially executing slow SQL.
  proxy-backend-executor-suitable: OLTP
#  proxy-frontend-max-connections: 0 # Less than or equal to 0 means no limitation.
#  sql-federation-enabled: false
#    # Available proxy backend driver type: JDBC (default), ExperimentalVertx
#  proxy-backend-driver-type: JDBC
</code></pre></div>
<p dir="auto">and then modify the sysbench oltp_common.lua, change the create table clause, make pad to char(200)<br>
start sysbench to test</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sysbench oltp_read_only --mysql-host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password='root' --mysql-db=encrypt_db --tables=10 --table-size=1000000 --report-interval=10 --time=3600 --threads=10 --max-requests=0 --percentile=99 --mysql-ignore-errors=&quot;all&quot; --rand-type=uniform --range_selects=off --auto_inc=off cleanup
sysbench oltp_read_only --mysql-host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password='root' --mysql-db=encrypt_db --tables=10 --table-size=1000000 --report-interval=10 --time=3600 --threads=10 --max-requests=0 --percentile=99 --mysql-ignore-errors=&quot;all&quot; --rand-type=uniform --range_selects=off --auto_inc=off prepare

sysbench oltp_point_select --mysql-host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password='root' --mysql-db=encrypt_db --tables=10 --table-size=1000000 --report-interval=5 --time=300 --threads=64 --max-requests=0 --percentile=99 --mysql-ignore-errors=&quot;all&quot; --range_selects=off --rand-type=uniform --auto_inc=off run | tee oltp_point_select_64.txt
"><pre class="notranslate"><code class="notranslate">sysbench oltp_read_only --mysql-host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password='root' --mysql-db=encrypt_db --tables=10 --table-size=1000000 --report-interval=10 --time=3600 --threads=10 --max-requests=0 --percentile=99 --mysql-ignore-errors="all" --rand-type=uniform --range_selects=off --auto_inc=off cleanup
sysbench oltp_read_only --mysql-host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password='root' --mysql-db=encrypt_db --tables=10 --table-size=1000000 --report-interval=10 --time=3600 --threads=10 --max-requests=0 --percentile=99 --mysql-ignore-errors="all" --rand-type=uniform --range_selects=off --auto_inc=off prepare

sysbench oltp_point_select --mysql-host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password='root' --mysql-db=encrypt_db --tables=10 --table-size=1000000 --report-interval=5 --time=300 --threads=64 --max-requests=0 --percentile=99 --mysql-ignore-errors="all" --range_selects=off --rand-type=uniform --auto_inc=off run | tee oltp_point_select_64.txt

</code></pre></div>
<p dir="auto">and you will get the following problem :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ERROR] 2022-01-13 16:21:43.226 [epollEventLoopGroup-3-7] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.lang.IllegalStateException: Mode must be either CBC or ECB.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:508)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.checkAndGetMode(SM4EncryptAlgorithm.java:123)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.sm4(SM4EncryptAlgorithm.java:103)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.encrypt(SM4EncryptAlgorithm.java:76)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.encrypt(SM4EncryptAlgorithm.java:72)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.encrypt(SM4EncryptAlgorithm.java:40)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.setCipherColumn(EncryptInsertValuesTokenGenerator.java:170)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.encryptToken(EncryptInsertValuesTokenGenerator.java:128)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.generateNewSQLToken(EncryptInsertValuesTokenGenerator.java:94)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.generateSQLToken(EncryptInsertValuesTokenGenerator.java:67)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.generateSQLToken(EncryptInsertValuesTokenGenerator.java:50)
	at org.apache.shardingsphere.infra.rewrite.sql.token.generator.SQLTokenGenerators.generateSQLTokens(SQLTokenGenerators.java:70)
	at org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext.generateSQLTokens(SQLRewriteContext.java:83)
	at org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry.createSQLRewriteContext(SQLRewriteEntry.java:78)
	at org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry.rewrite(SQLRewriteEntry.java:70)
	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.rewrite(KernelProcessor.java:59)
	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:47)
	at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:115)
	at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:67)
	at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:55)
	at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:62)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:96)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:69)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:384)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)"><pre class="notranslate"><code class="notranslate">[ERROR] 2022-01-13 16:21:43.226 [epollEventLoopGroup-3-7] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.lang.IllegalStateException: Mode must be either CBC or ECB.
	at com.google.common.base.Preconditions.checkState(Preconditions.java:508)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.checkAndGetMode(SM4EncryptAlgorithm.java:123)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.sm4(SM4EncryptAlgorithm.java:103)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.encrypt(SM4EncryptAlgorithm.java:76)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.encrypt(SM4EncryptAlgorithm.java:72)
	at org.apache.shardingsphere.encrypt.algorithm.SM4EncryptAlgorithm.encrypt(SM4EncryptAlgorithm.java:40)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.setCipherColumn(EncryptInsertValuesTokenGenerator.java:170)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.encryptToken(EncryptInsertValuesTokenGenerator.java:128)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.generateNewSQLToken(EncryptInsertValuesTokenGenerator.java:94)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.generateSQLToken(EncryptInsertValuesTokenGenerator.java:67)
	at org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptInsertValuesTokenGenerator.generateSQLToken(EncryptInsertValuesTokenGenerator.java:50)
	at org.apache.shardingsphere.infra.rewrite.sql.token.generator.SQLTokenGenerators.generateSQLTokens(SQLTokenGenerators.java:70)
	at org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext.generateSQLTokens(SQLRewriteContext.java:83)
	at org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry.createSQLRewriteContext(SQLRewriteEntry.java:78)
	at org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry.rewrite(SQLRewriteEntry.java:70)
	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.rewrite(KernelProcessor.java:59)
	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:47)
	at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:115)
	at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:67)
	at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:55)
	at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:62)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:96)
	at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:69)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:384)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)
</code></pre></div>
<h2 dir="auto">Bug Report</h2>
<p dir="auto">Mybatis mapper has jdbcType=LONGVARCHAR field. After sharding, the String type data is processed into StringReader type data. StringReader does not implement serialization interface, which eventually leads to serialization exception and data insertion failure</p>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">3.1.1</p>
<h3 dir="auto">Which project did you use? Sharding-JDBC or Sharding-Proxy?</h3>
<p dir="auto">Sharding-JDBC</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">insert success</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">insert fail</p>