Adding sorting to an Objectify query causes an empty result

I am experimenting with App Engine, Datastore, and Objectify 4. I have an Objectify work query that retrieves all objects of a given type from a data store. I am trying to sort the result based on date:

List<MyEntity> entities = OfyService.ofy().load().type(MyEntity.class).order("-createdDate").list();

But after adding the order, the query returns 0 records. This is my entity class:

@Entity
public class MyEntity
{   
    @Id Long id;
    Long userID;
    @Ignore String username;
    @Index String name;
    String url;
    String description;
    @Index Date createdDate;
    @Index int viewCount;
}

I tried to order other data types without success. Why is this happening?

+4
source share
2 answers

We need to define the index manually in WEB-INF / datastore-indexes.xml.

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes
  autoGenerate="true">
    <datastore-index kind="AppMedia" ancestor="false">
        <property name="createdDate" direction="desc" />
    </datastore-index>
</datastore-indexes>

, . . , .

+2

cloud.google.com , , " ", , @Index . "" , . , @Index , Objectify? ?

0

Source: https://habr.com/ru/post/1526264/


All Articles