mybatis-plus用的是3.3.0
資料庫使用DB2,主鍵是Int型別,自增
CREATE TABLE "XXX"."YYY" (
"STA_REF" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (
START WITH +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)
)
物體代碼:
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("XXX")
public class Tsksta implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "STA_REF", type = IdType.AUTO)
@TableField("STA_REF")
private Integer staRef;
@TableField("TSK_ID")
private Integer tskId;
。。。省略。。。
}
呼叫代碼:
tskstaService.saveBatch(lstTsksta2insert);
報錯資訊:
2020-03-23 21:33:02.010 ERROR 25868 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at org.apache.ibatis.executor.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]
at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129) ~[mybatis-3.5.3.jar:3.5.3]
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]
at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:252) ~[mybatis-3.5.3.jar:3.5.3]
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.lambda$saveBatch$0(ServiceImpl.java:134) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.executeBatch(ServiceImpl.java:324) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:129) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at com.baomidou.mybatisplus.extension.service.IService.saveBatch(IService.java:57) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at com.baomidou.mybatisplus.extension.service.IService$$FastClassBySpringCGLIB$$f8525d18.invoke(<generated>) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
試了下,其他表用saveBatch也報一樣的錯,用save單筆操作反而沒問題。
報錯為Jdbc3KeyGenerator.java
public void processBatch(MappedStatement ms, 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.getMetaData();
final Configuration configuration = ms.getConfiguration();
if (rsmd.getColumnCount() < keyProperties.length) {//rsmd這個為null導致的,請問這是為什么啊
// Error?
} else {
assignKeys(configuration, rs, rsmd, keyProperties, parameter);
}
} catch (Exception e) {
throw new ExecutorException("Error getting generated key or setting result to parameter object. Cause: " + e, e);
}
}小白請大神指教!
uj5u.com熱心網友回復:
DB2 有序列 sequence可以用序列做自增主鍵生成方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/110259.html
標籤:Java EE
上一篇:java eslipse
下一篇:求大師!
