0
First method is working fine but others has error. Why am i getting this error. 2 method have same purpose, one of them returns entity, others not.
**Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.x.y.z.entity.Customer#6542]
Object of class [com.x.y.z.entity.Customer#6542] optimistic locking failed nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction. **
@Override
@CacheEvict(cacheNames = CacheConstants.CUSTOMER_CACHE, key = "#customer.token + #customer.customerToken", cacheManager = "redisCacheManager")
public Customer updateCustomer(Customer customer) {
return repository.save(customer); // NO ERROR
}
@Override
public void updateCustomerStatus(Customer customer, TokenStatus status) {
customer.setStatus(status);
repository.save(customer); // ERROR (OPT. LOCK)
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCustomerStatus(Customer customer, TokenStatus status) {
customer.setStatus(status);
repository.save(customer); // ERROR (OPT. LOCK)
}
@Override
public void updateCustomerStatus(Customer customer, TokenStatus status) {
customer.setStatus(status);
repository.saveAndFlush(customer); // ERROR (OPT. LOCK)
}