Java 使用objectify对名称/值对象的列表属性上的数据存储实体进行排序
使用Google云数据存储,我想列出我的实体。 我想根据属性的名称,按属性的值检索它们 Java类模型:Java 使用objectify对名称/值对象的列表属性上的数据存储实体进行排序,java,google-cloud-datastore,objectify,Java,Google Cloud Datastore,Objectify,使用Google云数据存储,我想列出我的实体。 我想根据属性的名称,按属性的值检索它们 Java类模型: public class ContainerEntity { @Index String id; @Index private List<NameValueProperty> properties; } public class NameValueProperty { @Index private String name;
public class ContainerEntity {
@Index
String id;
@Index
private List<NameValueProperty> properties;
}
public class NameValueProperty {
@Index
private String name;
@Index
private String value;
}
我如何使用objectify实现这一点?
我尝试使用这段代码,但不起作用:
Query<ContainerEntity> query = ObjectifyService.ofy().load().type(ContainerEntity.class);
query = query.filter("properties.name = ", "propertyIWantToOrderBy")
.order("properties.value");
Query Query=ObjectifyService.ofy().load().type(ContainerEntity.class);
query=query.filter(“properties.name=,“propertyIWantToOrderBy”)
.订单(“财产价值”);
首先,它会过滤(我不希望如此),然后它看起来对名为“propertyIWantToOrderBy”的属性的顺序不正确。是否有解决方案/解决方法?要执行类似顺序的操作(“properties.value where properties.name='propertyIWantToOrderBy'”)此设计的要点是拥有一个动态实体
目标化版本:5.1.22
Jdk:8当您尝试对列表属性进行筛选和排序时,列表属性可能会令人困惑。请尝试以下方法:
public class ContainerEntity {
@Id
String id;
@Index
private Map<String, String> properties = new HashMap<>();
}
顺便说一句,您不需要
@Index
id,它们不是作为常规属性存储的。他们需要@Id
注释。是的,这就是我最后实现它的方式。谢谢
public class ContainerEntity {
@Id
String id;
@Index
private Map<String, String> properties = new HashMap<>();
}
ofy().load().type(ContainerEntity.class).order("properties.propertyIWantToOrderBy");