When I try to run the following line
List<MessageEntity> list =
ObjectifyService.ofy()
.load()
.type(MessageEntity.class)
.ancestor(Key.create(groupKey))
.order("dateSent")
.list();
I get the following error message:
"com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found. recommended index is:\n- kind: MessageEntity\n ancestor: yes\n properties:\n - name: dateSent\n\nThe suggested index for this query is:\n \n \n \n\n"
If I remove the .order("dateSent")
line it works fine and brings me all the coresponding entities in the datastore.
any idea what I could be doing wrong?
here's is my Entity Class
@Entity
public class MessageEntity implements EntityRoot {
@Parent
private Ref<GroupEntity> groupEntityRef;
@Id
private Long id;
private String message;
private String attachmentUrl;
private Ref<TenantUserEntity> sender;
@Index
private Long dateSent;
public MessageEntity(Ref<GroupEntity> groupEntityRef, String message, String attachmentUrl,
Ref<TenantUserEntity> sender, Long dateSent) {
this.groupEntityRef = groupEntityRef;
this.message = message;
this.attachmentUrl = attachmentUrl;
this.sender = sender;
this.dateSent = dateSent;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getAttachmentUrl() {
return attachmentUrl;
}
public void setAttachmentUrl(String attachmentUrl) {
this.attachmentUrl = attachmentUrl;
}
public Ref<TenantUserEntity> getSender() {
return sender;
}
public void setSender(Ref<TenantUserEntity> sender) {
this.sender = sender;
}
public Long getDateSent() {
return dateSent;
}
public void setDateSent(Long dateSent) {
this.dateSent = dateSent;
}
public Ref<GroupEntity> getGroupEntityRef() {
return groupEntityRef;
}
@EmptyConstructor
public MessageEntity() {
}
@Override
public Key<? extends EntityRoot> getKey() {
return Key.create(groupEntityRef.getKey(), MessageEntity.class, id);
}
}
P.S. I added the @Index annotation before creating the entities, while searching for this error I saw this as a common bug.