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.