I am trying to migrate my application from spring boot 2.2.6 to 2.3.6. This update also updates the spring-data-couchbase 3.2.6 to 4.0.2. Earlier version was throwing OptimisticLockingFailureException but with this upgrade the exception is never thrown. I am using the debugger to stop the execution just before persisting, then changing the data manually in couchbase UI and continue the execution. Exception is thrown in spring-data-couchbase 3.2.6 but not in 4.0.2
spring-data-couchbase 3.2.6
CouchbaseConfiguration.java
@Configuration
@EnableCouchbaseRepositories
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
@Value("${couchbase.cluster.bucketName}")
private String bucketName;
@Value("${couchbase.cluster.ip}")
private String ip;
@Value("${couchbase.cluster.password}")
private String password;
@Override
protected String getBucketName() {
return bucketName;
}
@Override
protected String getBucketPassword() {
return this.password;
}
@Override
protected List<String> getBootstrapHosts() {
return Arrays.asList(ip);
}
@Bean(name = BeanNames.COUCHBASE_TEMPLATE)
@Override
public CouchbaseTemplate couchbaseTemplate() throws Exception {
final CouchbaseTemplate template = super.couchbaseTemplate();
template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
return template;
}
@Override
protected Consistency getDefaultConsistency() {
return Consistency.READ_YOUR_OWN_WRITES;
}
PersistenceSnippet.java
entity = repository.findById(id)
try {
return Optional.of(repository.save(entity)); // stop execution here in debugger
} catch (OptimisticLockingFailureException e) {
log.warn("failed to persist optimistically");
return Optional.empty();
}
spring-data-couchbase 4.0.2
CouchbaseConfiguration.java
@Configuration
@EnableCouchbaseRepositories
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
@Value("${couchbase.cluster.bucketName}")
private String bucketName;
@Value("${couchbase.cluster.ip}")
private String ip;
@Value("${couchbase.cluster.password}")
private String password;
@Value("${couchbase.durability:lenient}")
private String durability;
@Override
public String getConnectionString() {
return ip;
}
@Override
public String getUserName() {
return bucketName;
}
@Override
public String getPassword() {
return password;
}
@Override
public String getBucketName() {
return bucketName;
}
Is it because of the difference of template.setWriteResultChecking(WriteResultChecking.EXCEPTION);? But couchbase template in 4.0.2 does not have any such method. Is there any configuration I am missing in 4.0.2 to be able to throw OptimisicLockingFailureExpception? My Entity object has @Version long version;
and @Document
annotations