Search code examples
google-app-enginejdojdoql

Appengine: DatastoreNeedIndexException when using "order by"


Hello I have this DatastoreNeedIndexException when I try to order by my query.

here is the code:

@PersistenceCapable
public class Gaze {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;

@Persistent
Blob image;

@Persistent
Long time;

@Persistent
Long TTL;

@Persistent
String town;

@Persistent
String countryCd;

@Persistent
String tag;

the query:

Query query = pm.newQuery(Gaze.class, "tag == tagParam");
    query.declareParameters("String tagParam");
    //query.setRange(0,10);
    query.setOrdering("time desc");
    List<Gaze> results = (List<Gaze>) query.execute(tag);

and the indexes:

<datastore-indexes autoGenerate="false">
<datastore-index kind="Gaze" ancestor="false">
<property name="tag"  direction="asc" />
<property name="time" direction="desc"/>
<property name="TTL"  direction="desc" />
</datastore-index>

I really don't know where to look. If I remove the order by I have my objects ordered by primarykeys


Solution

  • Are you sure that your indexes are created? You can check it in your Admin Console. Sometimes it takes a while...