Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.io.NotSerializableException occurred when setting parameters into PreparedStatement #2105

Closed
mydingwei opened this issue Mar 26, 2019 · 4 comments
Assignees

Comments

@mydingwei
Copy link

  • table_demo (id int primary key, column_a int, column_b longtext)

  • mybatis dynamic sql like this:

insert into table_demo (id, column_a, column_b) values ((#{id,jdbcType=VARCHAR}, #{columnA,jdbcType=INTEGER}, #{columnB,jdbcType=LONGVARCHAR})

If jdbcType of columnB is specified as org.apache.ibatis.type.JdbcType.LONGVARCHAR, this parameter will be handled in SimpleExecutor.preparedStatement(..) method, and then org.apache.ibatis.type.ClobTypeHandler.setNonNullParameter(..) method will be called.

Type of column_b will be packaged in StringReader, thus the parameters property's type in ShardingPreparedStatement will be set to StringReader.

Subsequently, replaySetParameter(final PreparedStatement preparedStatement, final List<Object> parameters) will be called in ShardingPreparedStatement's route() method.

When the code goes to each.invoke(preparedStatement);, com.mysql.jdbc.PreparedStatement.setObject(int parameterIndex, Object parameterObj) will be invoked, and StringReader cannot be identified by PreparedStatement, then setSerializableObject will be called, but StringReader doesnot implement Serializable, so java.io.NotSerializableException occur.

@mydingwei
Copy link
Author

version is 3.0.0.M1

@tuohai666
Copy link
Member

Thanks for your report, will be fixed in 4.0.0.

@tuohai666
Copy link
Member

Duplicate with #1567.
Will be fixed together.

@tuohai666
Copy link
Member

Fixed via #2388.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants