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

[错误报告]: 神通数据库使用mp saveBatch会报错 #6481

Open
3 tasks done
Jean-Jacques-Nuoan opened this issue Sep 11, 2024 · 0 comments
Open
3 tasks done

[错误报告]: 神通数据库使用mp saveBatch会报错 #6481

Jean-Jacques-Nuoan opened this issue Sep 11, 2024 · 0 comments

Comments

@Jean-Jacques-Nuoan
Copy link

Jean-Jacques-Nuoan commented Sep 11, 2024

确认

  • 我使用的版本是最新版, 并且使用插件确认过项目里无依赖版本冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

3.5.1

问题描述

神通数据库使用mp saveBatch会报错,配置@TableId(value = "id", type = IdType.ASSIGN_ID) 可以解决,但是需要根据数据库设置不同的值,Debug发现进入Jdbc3KeyGenerator.processBatch方法中stmt.getGeneratedKeys()返回结果为null,跟到OscarStatement的getGeneratedKeys()方法中this.result为null,后面就不知道怎么看了,不知道为什么单表插入没有问题,批量插入有问题。

详细堆栈日志

org.springframework.jdbc.UncategorizedSQLException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: Error
; uncategorized SQLException; SQL state [null]; error code [0]; Error; nested exception is java.sql.SQLException: Error
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
	at com.baomidou.mybatisplus.extension.toolkit.SqlHelper.executeBatch(SqlHelper.java:192)
	at com.baomidou.mybatisplus.extension.toolkit.SqlHelper.executeBatch(SqlHelper.java:217)
	at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.executeBatch(ServiceImpl.java:240)
	at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:136)
	at com.baomidou.mybatisplus.extension.service.IService.saveBatch(IService.java:73)
	at com.baomidou.mybatisplus.extension.service.IService$$FastClassBySpringCGLIB$$f8525d18.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
......
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Error
	at com.alibaba.druid.pool.DruidDataSource.handleConnectionException(DruidDataSource.java:1936)
	at com.alibaba.druid.pool.DruidPooledConnection.handleException(DruidPooledConnection.java:124)
	at com.alibaba.druid.pool.DruidPooledStatement.checkException(DruidPooledStatement.java:87)
	at com.alibaba.druid.pool.DruidPooledResultSet.checkException(DruidPooledResultSet.java:42)
	at com.alibaba.druid.pool.DruidPooledResultSet.getMetaData(DruidPooledResultSet.java:419)
	at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processBatch(Jdbc3KeyGenerator.java:80)
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:129)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122)
	at org.apache.ibatis.executor.CachingExecutor.flushStatements(CachingExecutor.java:114)
	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.plugin.Plugin.invoke(Plugin.java:64)
	at com.sun.proxy.$Proxy230.flushStatements(Unknown Source)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:249)
	at com.baomidou.mybatisplus.extension.toolkit.SqlHelper.lambda$executeBatch$1(SqlHelper.java:224)
	at com.baomidou.mybatisplus.extension.toolkit.SqlHelper.executeBatch(SqlHelper.java:182)
	... 122 common frames omitted
	Suppressed: java.sql.SQLException: Error
		at com.alibaba.druid.pool.DruidDataSource.handleConnectionException(DruidDataSource.java:1936)
		at com.alibaba.druid.pool.DruidPooledConnection.handleException(DruidPooledConnection.java:124)
		at com.alibaba.druid.pool.DruidPooledStatement.checkException(DruidPooledStatement.java:87)
		at com.alibaba.druid.pool.DruidPooledResultSet.checkException(DruidPooledResultSet.java:42)
		at com.alibaba.druid.pool.DruidPooledResultSet.close(DruidPooledResultSet.java:78)
		at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processBatch(Jdbc3KeyGenerator.java:87)
		... 135 common frames omitted
	Caused by: java.lang.NullPointerException: null
		at com.alibaba.druid.pool.DruidPooledResultSet.close(DruidPooledResultSet.java:74)
		... 136 common frames omitted
Caused by: java.lang.NullPointerException: null
	at com.alibaba.druid.pool.DruidPooledResultSet.getMetaData(DruidPooledResultSet.java:417)
	... 136 common frames omitted

跟踪相关代码

OscarStatement.class

    public ResultSet getGeneratedKeys() throws SQLException {
        if (this.autoGeneratedInfo == -1) {
            throw new OSQLException("OSCAR-00420", "88888", 420);
        } else if (this.result == null) {
            return null;
        } else if (!this.result.getStatusString().startsWith("21")) {
            return this.createResultSet(new Field[0], new ArrayList(), (String)null, 0, 0L);
        } else {
            String status = this.result.getStatusString();
            int updateCount = this.result.getResultCount();
            int insertOID = this.result.getInsertRowid();
            Field[] fields = new Field[1];
            List tuples = new ArrayList();
            fields[0] = new Field(this.connection, "GENERATED_KEY", 26, 4, 0, "GENERATED_KEY", "", "", (byte)0);
            byte[] rowIdByte = new byte[]{0};

            try {
                rowIdByte = String.valueOf(insertOID).getBytes(this.encoding.getEncoding());
            } catch (UnsupportedEncodingException var8) {
            }

            byte[][] tempTuple = new byte[][]{rowIdByte};
            tuples.add(tempTuple);
            return this.createResultSet(fields, tuples, status, updateCount, (long)insertOID);
        }
    }

Jdbc3KeyGenerator.class

    public void processBatch(MappedStatement ms, Statement stmt, Object parameter) {
        String[] keyProperties = ms.getKeyProperties();
        if (keyProperties != null && keyProperties.length != 0) {
            try {
                ResultSet rs = stmt.getGeneratedKeys();
                Throwable var6 = null;

                try {
                    ResultSetMetaData rsmd = rs.getMetaData();
                    Configuration configuration = ms.getConfiguration();
                    if (rsmd.getColumnCount() >= keyProperties.length) {
                        this.assignKeys(configuration, rs, rsmd, keyProperties, parameter);
                    }
                } catch (Throwable var17) {
                    var6 = var17;
                    throw var17;
                } finally {
                    if (rs != null) {
                        if (var6 != null) {
                            try {
                                rs.close();
                            } catch (Throwable var16) {
                                var6.addSuppressed(var16);
                            }
                        } else {
                            rs.close();
                        }
                    }

                }

            } catch (Exception var19) {
                throw new ExecutorException("Error getting generated key or setting result to parameter object. Cause: " + var19, var19);
            }
        }
    }
@Jean-Jacques-Nuoan Jean-Jacques-Nuoan changed the title [错误报告]: 描述 [错误报告]: 神通数据库使用mp saveBatch会报错 Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant