Michael Osofsky
Michael Osofsky

Reputation: 13115

Objectify can't find entity that appears to exist

I'm using Objectify 5.1.1 on Google App Engine. I have defined an Objectify entity called Insight and tried to query it by a boolean property called downloaded. However, Objectify can't find this entity.

Here's how I'm trying to do the query:

Query<Insight> insightQueryTemplate = ofy().load().type(Insight.class).
                filter("downloaded", false).first().safe();

Here's a stripped down class definition for Insight:

@com.googlecode.objectify.annotation.Entity
public class Insight {
    @com.googlecode.objectify.annotation.Id 
    public Long id;

    public boolean downloaded = false;

    public Insight () { }

}

When I look in the development server's datastore I can see the entity does exist but the downloaded property says "false (unindexed)" instead of simply "false".

I'm pretty sure this used to work with Objectify 3.1 so what am I doing wrong?

Upvotes: 0

Views: 236

Answers (1)

Michael Osofsky
Michael Osofsky

Reputation: 13115

I think the tag @com.googlecode.objectify.annotation.Index needs to be annotated on the class like this:

@com.googlecode.objectify.annotation.Entity
public class Insight {
    @com.googlecode.objectify.annotation.Id 
    public Long id;

    @com.googlecode.objectify.annotation.Index  // *** This was missing ***
    public boolean downloaded = false;

    public Insight () { }

}

According to https://cloud.google.com/appengine/docs/java/datastore/indexes#Java_Unindexed_properties, properties are either set with setProperty() or setUnindexedProperty(). But the current documentation for Objectify says that properties are set as unindexed by default.

So I annotated my class with @com.googlecode.objectify.annotation.Index and the problem was fixed.

Upvotes: 2

Related Questions