dae
dae

Reputation: 23

Google Datastore Querys return stale data

I`m using Google App Engine and when I remove from the datastore and I list again the results, I recover stale data. What is the problem? Here is the code I use.

public void remove(long id) {
    EntityManager em = EMFService.get().createEntityManager();
    try {
      Todo todo = em.find(Todo.class, id);
      em.remove(todo);
    } finally {
      em.close();
    }
  }

  public List<Todo> getTodos(String userId) {
    EntityManager em = EMFService.get().createEntityManager();
    Query q = em
        .createQuery("select t from Todo t where t.author = :userId");
    q.setParameter("userId", userId);
    List<Todo> todos = q.getResultList();
    System.out.println("Listado de " + userId  + ": " + todos);
    return todos;
  }

Upvotes: 2

Views: 297

Answers (1)

Alexander Trakhimenok
Alexander Trakhimenok

Reputation: 6268

AppEngine use HRD that is "eventually consistant.

Read more here: https://developers.google.com/appengine/docs/java/datastore/structuring_for_strong_consistency

Upvotes: 3

Related Questions