With Spring-data-couchbase, retrieve document from couchbase not updated


#1

I use spring-data-couchbase to retrieve couchbase, connect with bucket.

However, whenever the programme first time retrieve this object, it never success, must retrieve the second time than could get the document from couchbase.

Is it any possible that maybe some cache here?


#2

You are describing a consistency issue here. If you want consistent data you need to specify it in your request. If you are using the first version of SpringDataCouchbase you can do it like

ViewQuery viewQuery = ViewQuery.from("customer", "all");
viewQuery.stale(Stale.FALSE);
couchbasetemplate.findByView(viewQuery, Customer.class);

If you use the latest version of Spring Data Couchbase you can define a default consistency level by setting the following property:

 spring.data.couchbase.consistency=read-your-own-writes

This is the default consistency level in the Spring Boot Starter AutoConfig since yesterday :slight_smile:


#3

I use Repository, which all in standard:

  1. For entity class,
    @Document
    public class Aaa {
    @Id private String column1;

  2. For repository
    public interface AaaRepository extends CrudRepository<Aaa, String> {

  3. For config class, is:
    @Configuration
    @EnableCouchbaseRepositories(“correct repository package”)
    @EnableConfigurationProperties(CouchbaseConfiguration.class)
    public class CouchbaseConfig extends AbstractCouchbaseConfiguration {

  4. For service class, call like:
    final Iterable payments = AaaRepository.findAll();
    ===========================================================================

Like that, then the problam appear: When first time programe read one object, data is not consistence, and get the correct object status after the second time query, but two queries are exactly the same


#4

I use Repository, which all in standard:1) For entity class,@Documentpublic class Aaa { @Id private String column1;.

  1. For repositorypublic interface AaaRepository extends CrudRepository {

  2. For config class, is:@Configuration@EnableCouchbaseRepositories(“correct repository package”)@EnableConfigurationProperties(CouchbaseConfiguration.class)public class CouchbaseConfig extends AbstractCouchbaseConfiguration {

  3. For service class, call like:final Iterable payments = AaaRepository.findAll();===========================================================================

Like that, then the problam appear: When first time programe read one object, data is not consistence, and get the correct object status after the second time query, but two queries are exactly the same


#5

Could you please also tell us which version you are using?


#6

Idoguin, thank you for your care and tracing my question.

  1. I am using 1.4.1.RELEASE
  2. My repository is like that:
    public interface AaaRepository extends CrudRepository<Aaa, String> {}
  3. My service direct call: AaaRepository.findAll();
  4. Should call the second time than retrieve new saved document, however, new saved document is also operated by the same project

#7

If you are using version 1.4.1 and want strong consistency, you need to use the lower level API.

ViewQuery viewQuery = ViewQuery.from("customer", "all");    
viewQuery.stale(Stale.FALSE);
couchbasetemplate.findByView(viewQuery, Customer.class);

This is not mandatory with the latest release: http://blog.couchbase.com/2016/february/spring-data-couchbase-2-is-out-quick-getting-started-with-spring-initializr


#8

Hi Idoguin,

Thank you very much, I fixed the issue!!!

Just one tiny thing:
ViewQuery viewQuery = ViewQuery.from(“customer”, “all”); //we assume that there is a class named Customer.class here

Would you tell me how “customer” and “all”, these two value come from?
is it only because there is a class Customer.class, thus its name is “customer”?
and how about “all” ?


#9

The design document name customer is indeed the lower case Class name.
The repository has a findAll method, so the view backing up this method is called ‘all’.
If you add the findSomething method in the repository, the view will need to be names ‘something’.

Note that all of these has been simplified with Spring Data Couchbase 2.