【问题标题】:Objectify Google DataSore Query对象化 Google DataStore 查询
【发布时间】:2012-05-28 10:19:15
【问题描述】:

事情是这样的 :-) 我们有两个类,AppointmentHairdresser,它们都具有相同的一个祖先(静态最终密钥: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();

为了更清楚一些,这是 Appointment 的设置方式:

@Unindexed

公共类约会实现可序列化{

@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;

【问题讨论】:

  • 您是否为所有这些字段创建了跨 {ancestor, hairdresserKey, timeSlot, LENGTH} 单属性索引的多属性索引?

标签: java objectify


【解决方案1】:

找到这个:

这几乎肯定是一个索引问题。为了使该查询起作用,您必须定义两个索引:

referenceKeyToC 上的单一属性索引 {ancestor, referenceKeyToC} 上的多属性索引 在 Objectify 3.x 中,属性默认具有单属性索引,但如果您已将 @Unindexed 添加到类 B 中,则需要将 @Indexed 放在 referenceKeyToC 上。 多属性索引在 datastore-indexes.xml 中定义。如果您在开发模式下运行此查询,环境应该为您提供所需的 xml 的 sn-p。

成功了!感谢您指出正确的方向!

【讨论】:

    猜你喜欢
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多