批量更新从update [0]返回意外的行数;实际行数:0;预期:PagingAndSortingRepository中{1}

时间:2017-04-12 08:56:33

标签: spring-boot spring-data-jpa

我正在尝试使用SpringJpa保存方法插入一些记录,但它给了我以下错误

`2017-04-12 14:06:55.765  INFO 9100 --- [nio-8090-exec-9] o.h.e.j.b.internal.AbstractBatchImpl     : HHH000010: On release of batch it still contained JDBC statements
2017-04-12 14:06:55.771 ERROR 9100 --- [nio-8090-exec-9] o.a.c.c.C.[.[.[/].
[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] 
in context with path [] threw exception [Request processing failed; nested 
exception is 
org.springframework.orm.ObjectOptimisticLockingFailureException: Batch 
update returned unexpected row count from update [0]; actual row count: 0; 
expected: 1; nested exception is org.hibernate.StaleStateException: Batch 
update returned unexpected row count from update [0]; actual row count: 0; 
expected: 1] with root cause

org.hibernate.StaleStateException: Batch update returned unexpected row 
count from update [0]; actual row count: 0; expected: 1
at 


org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:81) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:63) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3281) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]`

我已在此门户网站中搜索过该解决方案但未获得解决方案。

我使用以下代码从我的服务类中插入数据

Collection<? extends CcttBulletinProductEntity> lstExistingSerial = ccttBulletinProductJpaRepository
            .findByCompositePrimaryKeyBulletinNumAndCompositePrimaryKeyRevId(
                    productSerial.getBulletinNum(), revId.getRevId() - 1);
    lstExistingSerial.forEach(p -> p.setRevId(null));
    lstExistingSerial.forEach(p -> p.setRevId(revId.getRevId()));
    lstExistingSerial.forEach(p -> p.setLastUpdatedBy(productSerial
            .getLastUpdatedBy()));
    lstExistingSerial.forEach(p -> p.setLastUpdatedDate(productSerial
            .getLastUpdatedDate()));
    for (CcttBulletinProductEntity existingSerial : lstExistingSerial) {
        lstBulletinProducts.add(existingSerial);
    }
    ccttBulletinProductJpaRepository.save(lstBulletinProducts);
  

我的存储库是

public interface CcttBulletinProductJpaRepository
    extends
    PagingAndSortingRepository<CcttBulletinProductEntity, CcttBulletinProductEntityKey> {

Collection<? extends CcttBulletinProductEntity> findByCompositePrimaryKeyBulletinNumAndCompositePrimaryKeyRevId(
        String bulletinNum, Integer revId);

@Override
public <S extends CcttBulletinProductEntity> Iterable<S> save(
        Iterable<S> entities);

}

我的表中有复合主键,因此我使用了两个实体,如

  

CcttBulletinProductEntity.java和CcttBulletinProductEntityKey.java

0 个答案:

没有答案