[英]Objectify Google DataSore Query
事情是这样的:-)我们有两个类, Appointment
和Hairdresser
,它们具有相同的类,一个祖先(一个静态的最终键: topParent
)代表HairSalon
键。 Appointment
包含如下的Hairdresser
:
@Parent
public Key parent;
public Key hairdresserKey;`
但是当我们尝试过滤约会时,它不会得出结果。 hairdresserKey == null
的父级可能是一个线索,但是现在我们有点卡住了。
那么有人可以告诉我们此查询出了什么问题吗?
非常感谢!
appointment.hairdresserKey = new Key<Hairdresser>(topParent, Hairdresser.class, appointment.hairdresser.id);
appointment.parent = topParent;
Key<Hairdresser> queryKey = new Key<Hairdresser>(topParent, Hairdresser.class, appointment.hairdresser.id);
Objectify ofyTransaction = ObjectifyService.beginTransaction();
try {
List<Key<Appointment>> previousTimeSlotOneHour = ofyTransaction.query(Appointment.class)
.ancestor(topParent)
.filter("hairdresserKey", appointment.hairdresserKey)
.filter("timeSlot", appointment.timeSlot.getPreviousTimeSlot())
.filter("LENGTH", 1.0d).listKeys();
为了进一步说明,这是约会设置的方式:
@Unindexed
公共类约会实现Serializable {
@Id
public Long id;
@Indexed
public TimeSlot timeSlot;
@Transient
public WorkDay workDay;
@Transient
public Customer customer;
public Key customerKey;
public int END_TIME_HOUR;
public int END_TIME_MINUTES;
@Indexed
public TREATMENT treatment = TREATMENT.TREATMENT_CUT;
public int revisionNumber = -1;
/* QUERY Fields */
@Indexed
private String stringDate;
private double LENGTH;
@Parent
public Key parent;
private Date date;
@Transient
public Hairdresser hairdresser;
public Key hairdresserKey;
发现了这一点:
这几乎可以肯定是一个索引问题。 为了使该查询起作用,必须定义两个索引:
在referenceKeyToC上的单属性索引在{ancestor,referenceKeyToC}上的多属性索引在Objectify 3.x中,属性默认情况下具有单属性索引,但是如果将@Unindexed添加到类B,则需要将@在referenceKeyToC上建立索引。 多属性索引在datastore-indexes.xml中定义。 如果您以开发人员模式运行此查询,则环境应为您提供所需的xml代码段。
这奏效了! 感谢您指出正确的方向!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.