Adelin Adelin - 4 months ago 17
Java Question

Unable to get object from datastore using objectify

I am working on a simple expenses manager that will be deployed on google appengine. I am using objectify as Appengine ORM. now the problem is that I am unable to get a simple Object from datastore. The Session here is always null !! But when I check it out in localhost datastore I can see that it is there !

public String findEmailBySessionId(String sid) {
Session session = datastore.load().type(Session.class).id(sid).now();
if (session != null && (session.getDate().after(new Date()) || session.isToBeRemembered())) {
return session.getEmail();
} // this is always null !
return null;

public class Session {

private String email;

private String sessionId;

private Date date;

private boolean toBeRemembered;

private Key<User> parent;

public class User {

private String email;

private String name;
private String password;
private Date dateOfBirth;
private String hashSalt;

public User() {


Ok, I've got the answer and it is very silly. It is actually very stupid.

In google documentation there is a restriction on query that says:

*Filtering on unindexed properties returns no results !!!! * link For objectify to index a property that property should be annotated with @Index annotation. In the code above I forgot to put @Index annotation on date ! And this was the problem. After I put the annotation back everything returned to normal.