opengaussjdbc问题整理

opengauss-jdbc问题整理(更新中)

问题 1 jdbc 批量执行 insert 语句时返回结果不符合 Spring jpa 预期

问题描述:

jdbc 执行查询时,可以使用preparestatment.executeBatch()方法批量执行一组 sql 语句,该方法返回为int[]int 型数组变量,含义是批量执行的每个 sql 语句更新的数据行数。通过 spiring jpa 批量执行相同格式的语句时(例如insert into table1 values (?, ?, ? , ?),批量执行 5 次 ),预期返回的 int 型数组值为[1, 1, 1, 1, 1],实际返回结果为[5, 0, 0, 0, 0],与预期部分,导致如下报错:

Caused by: org.springframework.orm.jpa.JpaSystemException: Batch update returned unexpected row count from update [0]; actual row count: XX; expected: 1; nested exception is org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: XX; expected: 1 at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:331)