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

向含有text字段类型的分表中插入数据时失败 #59

Closed
dzxiang opened this issue May 6, 2016 · 10 comments
Closed

向含有text字段类型的分表中插入数据时失败 #59

dzxiang opened this issue May 6, 2016 · 10 comments

Comments

@dzxiang
Copy link

dzxiang commented May 6, 2016

MyBatis+MySQL,向含有text字段类型的分表中插入数据数据时失败,异常信息如下:

Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:3887)
at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3603)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:2923)
at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setObject(FilterAdapter.java:1298)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:2920)
at com.alibaba.druid.filter.FilterAdapter.preparedStatement_setObject(FilterAdapter.java:1298)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_setObject(FilterChainImpl.java:2920)
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.setObject(PreparedStatementProxyImpl.java:411)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.setObject(DruidPooledPreparedStatement.java:476)
at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.setParameters(ShardingPreparedStatement.java:188)
at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.routeSQL(ShardingPreparedStatement.java:163)
at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.routeIfNeed(ShardingPreparedStatement.java:151)
at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.getRoutedPreparedStatements(ShardingPreparedStatement.java:138)
at com.dangdang.ddframe.rdb.sharding.jdbc.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:107)

Caused by: java.io.NotSerializableException: java.io.StringReader
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:3876)

@dzxiang dzxiang changed the title 向含有text和blob字段类型的分表中插入数据时失败 向含有text字段类型的分表中插入数据时失败 May 13, 2016
@dzxiang
Copy link
Author

dzxiang commented Jun 20, 2016

大家都没有碰到过这个问题吗?

@hzlzz
Copy link

hzlzz commented Jun 28, 2016

我也碰到了这个问题 请问有解决方案吗

@dzxiang
Copy link
Author

dzxiang commented Jun 28, 2016

在:com.dangdang.ddframe.rdb.sharding.jdbc.adapter.AbstractPreparedStatementAdapter中临时打了一个小补丁:
private void setParameter(final int index, final Object x) throws SQLException {
int extendedSize = index - parameters.size();
if (extendedSize > 1) {
while (--extendedSize > 0) {
parameters.add(null);
}
}
if(x instanceof java.io.StringReader){
Reader reader = (Reader)x;
BufferedReader r = null;
StringBuilder b = new StringBuilder();
String line;
try {
r = new BufferedReader(reader);
boolean first = true;
String ls = System.getProperty("line.separator");
while((line=r.readLine())!=null) {
if(first) first = false;
else b.append(ls);
b.append(line);
}

            String y = b.toString();
            parameters.add(index - 1,y);
        } catch (IOException e) {
            e.printStackTrace();
            throw new SQLException(e);
        } finally{
            if(r!=null){
                try {
                    r.close();
                } catch (IOException e) {}
            }
        }
    }
    else{
        parameters.add(index - 1, x);   
    }
}

@billForgithub
Copy link

我也碰到了这个问题

@duran-zhu
Copy link

修复这个bug的代码会导致使用mybatis自增id出错。
在insert语句后,执行select last_insert_id() from dual出现空指针问题。

@shuohao
Copy link

shuohao commented Nov 23, 2018

我也遇到了 请问这个现在如何解决啊

@runbestfast
Copy link

3.0也有这个问题,#{reqMsg,jdbcType=LONGVARCHAR}
如果是非基础类型,mysql的jdbc驱动调用了
com.mysql.cj.AbstractQueryBindings#setObject
com.mysql.cj.AbstractQueryBindings#setSerializableObject
stringReader不能序列化,抛出异常
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Invalid argument value: java.io.NotSerializableException

@shenmimoon
Copy link

3.0也有这个问题,#{reqMsg,jdbcType=LONGVARCHAR}
如果是非基础类型,mysql的jdbc驱动调用了
com.mysql.cj.AbstractQueryBindings#setObject
com.mysql.cj.AbstractQueryBindings#setSerializableObject
stringReader不能序列化,抛出异常
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Invalid argument value: java.io.NotSerializableException

+1

@shuohao
Copy link

shuohao commented Nov 28, 2018

对 jdbctype为longvarchar就会报这个错

@terrymanu
Copy link
Member

For English only, other languages will not accept.
I just lock this issue. If you want, you can submit a new issue with English

@apache apache locked and limited conversation to collaborators Nov 28, 2018
@apache apache unlocked this conversation Dec 12, 2018
@apache apache locked and limited conversation to collaborators Dec 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants