Objectify投影查询返回null

时间:2015-03-24 01:04:01

标签: android google-cloud-datastore objectify

我似乎无法让我的投影查询返回除null之外的任何内容,不确定我做错了什么。 这是我设置并调用查询的代码:

    Query query1 = OfyService.ofy().load().type(CargoEntity.class).
       project("imageUrl", "latitude", "longitude").distinct(false); //filter("group", group);

    // Execute the query:
    List<Entity> results = query1.list();

    logger.warning("(Query from datastore results.isEmpty()) : " + (results.isEmpty()));
    logger.warning("(Group = ) : " + group);

    if (!results.isEmpty()) {
        logger.warning("(Query from datastore results.size()) : " + (results.size()));
        //Create STRTree-Index.
        STRtree strTree = new STRtree();
        GeometryFactory gf = new GeometryFactory();

        //Loop through the  result list from DataStore.
        for (Entity result : results) {

            STRLeaf leaf = new STRLeaf((float)result.getProperty("latitude"), (float)result.getProperty("longitude"), (String)result.getProperty("imageUrl"));

            Coordinate coord = new Coordinate(leaf.getLongitude(), leaf.getLatitude());

            Point point = gf.createPoint(coord);

            //Add result to index.
            strTree.insert(point.getEnvelopeInternal(), leaf);
        }

我真的很陌生,所以它可能是我想念的明显事物。我确实在开发人员控制台中看到了索引。以下是我的实体中的属性:

@Entity
@Index
@Cache
public class CargoEntity {

//datastore key
@Id
private String imageUrl;
private float latitude;
private float longitude;
private String group;
@Unindex
private int rating;
@Unindex
private Blob image;
@Unindex
private String email;
@Unindex
private String userName;
@Unindex
private String description;
@Unindex
private Date date;
@Unindex
private String blobKey;
@Unindex
private String type;
@Unindex
private boolean flag;
@Unindex
private int photoOrientation;

public CargoEntity() {
}
//getters and setters below

1 个答案:

答案 0 :(得分:1)

所以显然我是将实体id添加到不允许的投影查询中(或者它被允许但返回null)。这篇文章回答了这个问题。

Google App Engine projection query returns 0 results

相关问题