【问题标题】:Objectify projection queries returning null对象化投影查询返回 null
【发布时间】:2015-03-24 01:04:00
【问题描述】:

我似乎无法让我的投影查询返回除 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

【问题讨论】:

  • 您是否为这三个字段定义了多属性索引?
  • 在数据存储下的开发人员控制台中 - 索引我看到索引 CargoEntity 组 ▲ + imageUrl ▲ + latitude ▲ + longitude ▲---- imageUrl ▲ + latitude ▲ + longitude ▲ ---- state ▲ + imageUrl ▲ + 纬度 ▲ + 经度 ▲----
  • 我在数据存储中添加了一个新的多属性索引,并运行了这个过滤后的查询,它返回了一个非空结果。查询 query1 = OfyService.ofy().load().type(CargoEntity.class).filter("group", group).filter("latitude >", 0.0);这行得通,所以我认为问题出在投影查询调用中。我寻找其他使用 Objectify 投影查询的人的例子,但我找不到。
  • 这里是测试用例。如果您可以添加一个中断,请提交 PR:github.com/objectify/objectify/blob/master/src/test/java/com/…

标签: android google-cloud-datastore objectify


【解决方案1】:

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

Google App Engine projection query returns 0 results

【讨论】:

    猜你喜欢
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-14
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多