CannotAcquireLockException问题

时间:2013-11-08 05:58:39

标签: java mysql spring hibernate jpa

我的功能就像我想插入用户地址,用户可以有多个地址,即使用户可以将其中一个地址标记为默认地址,下面是我的代码。 如果用户输入地址并将该地址标记为默认地址,我们会将其他地址默认标记重置为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 个答案:

没有答案