Home > Back-end >  MybatisPlus use saveBatch null Pointers, single save no problem, instead
MybatisPlus use saveBatch null Pointers, single save no problem, instead

Time:10-05

Mybatis - plus using 3.3.0
Using the DB2 database, the primary key is type Int, since the increasing
 CREATE TABLE "XXX". "YYY" (
"STA_REF INTEGER NOT NULL" GENERATED BY DEFAULT AS IDENTITY (
START WITH a + 1
INCREMENT BY + 1
MINVALUE + 1
MAXVALUE + 2147483647
NO CYCLE
CACHE 20
NO ORDER),
"TSK_ID" INTEGER,
"CMD_ID VARCHAR (50),
"DTA_DTE" DATE,
"STA_STS" CHAR (1),
"RMK VARCHAR (2048)
)

The entity code:
 @ Data 
@ EqualsAndHashCode (callSuper=false)
@ Accessors (chain=true)
@ TableName (" XXX ")
Public class Tsksta implements Serializable {

private static final long serialVersionUID=1L;

@ TableId (value="https://bbs.csdn.net/topics/STA_REF", type=IdType. AUTO)
@ TableField (" STA_REF ")
Private Integer staRef;

@ TableField (" TSK_ID ")
Private Integer tskId;
Omit,,,,,,
}

The calling code:
 tskstaService. SaveBatch (lstTsksta2insert); 

Error message:
 2020-03-23 21:33:02. 010 ERROR 25868 - O.A.C.C.C. [nio - 8888 - exec - 1]. [[. [/] [dispatcherServlet] : Servlet. The service () for the Servlet [dispatcherServlet] in context with the path [] threw the exception [Request processing failed; nested exception is org. Mybatis. Spring. MyBatisSystemException: nested exception is org. Apache. The ibatis. Executor. ExecutorException: ERROR getting generated key or setting the result to the parameter object. The Cause: Java lang. NullPointerException] with root Cause 

Java. Lang. NullPointerException: null
The at org. Apache. Ibatis. Executor. The keygen. Jdbc3KeyGenerator. ProcessBatch (Jdbc3KeyGenerator. Java: 78) ~ [mybatis - 3.5.3. Jar: 3.5.3]
At com. Baomidou. Mybatisplus. Core. Executor. MybatisBatchExecutor. DoFlushStatements (MybatisBatchExecutor. Java: 139) ~ [mybatis - plus - core - 3.3.0. Jar: 3.3.0]
The at org. Apache. Ibatis. Executor. BaseExecutor. FlushStatements (BaseExecutor. Java: 129) ~ [mybatis - 3.5.3. Jar: 3.5.3]
The at org. Apache. Ibatis. Executor. BaseExecutor. FlushStatements (BaseExecutor. Java: 122) ~ [mybatis - 3.5.3. Jar: 3.5.3]
At com. Baomidou. Mybatisplus. Core. Executor. MybatisCachingExecutor. FlushStatements (MybatisCachingExecutor. Java: 208) ~ [mybatis - plus - core - 3.3.0. Jar: 3.3.0]
The at org. Apache. Ibatis. Session. Defaults. DefaultSqlSession. FlushStatements (DefaultSqlSession. Java: 252) ~ [mybatis - 3.5.3. Jar: 3.5.3]
At com. Baomidou. Mybatisplus. The extension. Service. The impl. ServiceImpl. Lambda $saveBatch $0 (ServiceImpl. Java: 134) ~ [mybatis - plus - the extension - 3.3.0. Jar: 3.3.0]
At com. Baomidou. Mybatisplus. The extension. Service. Impl. ServiceImpl. ExecuteBatch (ServiceImpl. Java: 324) ~ [mybatis - plus - the extension - 3.3.0. Jar: 3.3.0]
At com. Baomidou. Mybatisplus. The extension. Service. Impl. ServiceImpl. SaveBatch (ServiceImpl. Java: 129) ~ [mybatis - plus - the extension - 3.3.0. Jar: 3.3.0]
At com. Baomidou. Mybatisplus. The extension. Service. IService. SaveBatch (IService. Java: 57) ~ [mybatis - plus - the extension - 3.3.0. Jar: 3.3.0]
At com. Baomidou. Mybatisplus. The extension. Service. $$$$f8525d18 FastClassBySpringCGLIB IService. Invoke (& lt; Generated>) ~ [mybatis - plus - the extension - 3.3.0. Jar: 3.3.0]
The at org. Springframework. Additional. Proxy. MethodProxy. Invoke (MethodProxy. Java: 204) ~ [spring - core - 4.3.21. The jar: 4.3.21. RELEASE]
At org. Springframework. Aop. Framework. CglibAopProxy $CglibMethodInvocation. InvokeJoinpoint (CglibAopProxy. Java: 736) ~ [spring aop -- 4.3.21. The jar: 4.3.21. RELEASE]
At org. Springframework. Aop. Framework. ReflectiveMethodInvocation. Proceed (ReflectiveMethodInvocation. Java: 157) ~ [spring aop -- 4.3.21. The jar: 4.3.21. RELEASE]


Tried, the same as the other table with saveBatch fault, use the save instead of single operation no problem,
An error for Jdbc3KeyGenerator. Java
 public void processBatch (MappedStatement ms, the Statement STMT, Object parameter) {
Final String [] keyProperties=Ms. GetKeyProperties ();
If (keyProperties==null | | keyProperties. Length==0) {
return;
}
Try (ResultSet rs=STMT. GetGeneratedKeys ()) {
Final ResultSetMetaData RSMD=rs. For getMetaData ();
The final Configuration Configuration=Ms. GetConfiguration ();
If (RSMD. GetColumnCount () & lt; KeyProperties. Length) {//RSMD this is null, is this why ah
//Error?
} else {
AssignKeys (configuration, rs, RSMD, keyProperties parameter).
}
} the catch (Exception e) {
Throw new ExecutorException (" Error getting generated key or setting the result to the parameter object. The Cause: "+ e, e);
}
}


Small white great god give advice or comments, please!

CodePudding user response:

DB2 has a sequence sequence

Can be made on the primary key sequence generation method