문제

Here is my simple entity:

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable 

public class Food {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key id;
    @Persistent
    private String name;
    @Persistent
    private String description;
    public Key getId() {
        return (id);
    }
    public void setId(Key id) {
        this.id = id;
    }
    public String getName() {
        return (name);
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getDescription() {
        return (description);
    }
    public void setDescription(String description) {
        this.description = description;
    }
}

And I'm loading my foods List this way:

try {
            pm = PMF.get().getPersistenceManager();
            Query q = pm.newQuery(Food.class);
            foods = (List<Food>) q.execute();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        finally {
            pm.close();
        }

The Key is automatically generated for every Food entity. I'm using also HRD. So... the query above (pm.newQuery(Food.class);) is not with strong consistency and one time is returning all results , second time is not returning the newly created foods. How to change this query in such way, that every time I get all foods from the database. In datastore documentation I've read that should be ancestor query, but I don't have ancestor path. (I should say that I'm new in datastore and still learning from yesterday but this one took me to much time). Please help me.

도움이 되었습니까?

해결책 2

You can't achieve strong consistency without using a parent. That's the whole point. Either you use ancestors, or you accept that sometimes your query results will be stale (and use eg memcache to get around that).

다른 팁

Two excellent and easy to understand video's about the workings of the App engine datastore and strong consistency:

Part-1: Datastore Introduction

https://www.youtube.com/watch?v=fQazhzcC-rg

Part-2: Datastore Query, Index and Transaction

https://www.youtube.com/watch?v=d4CiMWy0J70#t=645

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top