在我的数据存储中,我有一个帖子实体,它有一个发件人,这个发件人有一个位置列表。基本上,这看起来像这样:
@Entity
@Cache
@Unindex
@Searchable
public class Post {
@Index
@Load(WithSender.class)
@NonNull @Getter @Setter
protected Ref<User> sender;
@Index
@Getter
protected long creation;
}
@Entity
@Cache
@Unindex
public class User {
@Index
@NotNull
@Email
@NonNull
@Getter
@Setter
private String email;
@Size(max = 50)
@Getter
@Setter
private String firstName;
@Size(max = 50)
@Getter
@Setter
private String lastName;
@Index
@Setter
@Getter
protected List<Key<Region>> regions;
}
我想要做的是,能够查询属于该用户区域列表中某个区域的用户发送的所有帖子,并按创建顺序查询。
基本上,我尝试这样做:
query = query.filter("sender.regions", "key").order("-creation");
当我第一次执行查询时,AppEngine 要求我创建这个索引:
<datastore-index kind="Post" ancestor="false" source="manual">
<property name="sender.regions" direction="asc"/>
<property name="creation" direction="desc"/>
</datastore-index>
但结果仍然是无可救药的空...如果有人有建议,我会很高兴。谢谢!
最佳答案
为了通过“sender.regions”查询帖子,应该嵌入发件人实体。
数据存储中没有像“join”这样的 SQL。您可以将发件人嵌入到帖子中,或者先按地区查询发件人键,然后使用这些发件人键查询帖子。
希望对您有所帮助。
关于java - 在嵌入式引用列表中对象化查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29152333/