有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java CannotAcquireLockException问题

我的功能就像我想插入用户地址,用户可以有多个地址,甚至用户可以将其中一个地址标记为默认地址,下面是我的代码。 若用户输入地址并将该地址标记为默认地址,我们将把代码中显示的其他地址默认标志重置为false

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
public Address store(Address address){
    Assert.notNull(address, "address can not be null");
    resetDefault(address);
    Address createdAddress = this.create(address);
    return createdAddress;
}

在哪里

private void resetDefault(Address address) {
    if (address.isDefault())
        resetDefaultAddress(address);
}

 private void resetDefaultAddress(Address address) {
    addressRepository.unsetDefaultAddress(address.getAssociationId(),
            address.getCategory());
}

我们使用了JPA存储库

@Modifying
@Query("update Address a set a.defaultAddress = false where a.defaultAddress = true and a.associationId =:associationId and a.category =:category")
int unsetDefaultAddress(@Param("associationId") String associationId,
        @Param("category") AddressCategory category);

现在我的问题是,它在开发人员环境中运行良好,但当我们对应用程序进行负载测试时,我们得到了100个并发请求

org.springframework.dao.CannotAcquireLockException: Could not execute JDBC batch update; SQL [insert into wsc_address (address1, address2, address3, alias, associationId, attributes, category, city, country, defaultaddress, email1, email2, firstname, lastaccesstimestamp, lastname, phone1, phone2, phone3, postalcode, province, status, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.LockAcquisitionException: Could not execute JDBC batch update
Caused by: org.hibernate.exception.LockAcquisitionException: Could not execute JDBC batch update

我们使用的是MySql数据库

或者解决我的目的并提高性能的任何单个查询

我还注意到,在注释掉resetDefault(地址)之后;从存储方法来看,它运行良好


共 (0) 个答案