Java 将Google数据存储查询对象化

Java 将Google数据存储查询对象化,java,objectify,Java,Objectify,事情是这样的:-) 我们有两个类,约会和理发师,它们都有相同的祖先(一个静态的最终键:topParent),代表美发店键。约会包含的理发师如下: @Parent public Key parent; public Key hairdresserKey;` 但当我们试图过滤掉约会时,却没有结果。hairdresserKey==null中的父项,这可能是一个线索,但我们现在有点卡住了 有人能告诉我们这个问题出了什么问题吗 非常感谢 appointment

事情是这样的:-) 我们有两个类,
约会
理发师
,它们都有相同的祖先(一个静态的最终键:
topParent
),代表
美发店
键。
约会
包含的
理发师
如下:

    @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();
公共类约会实现可序列化{

@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上的单个属性索引 {祖先,referenceKeyToC}上的多属性索引 在Objectify 3.x中,默认情况下属性只有一个属性索引,但是如果您已经将@Unindexed添加到类B中,那么您需要将@Indexed放在referenceKeyToC上。 多属性索引在datastore-indexes.xml中定义。如果您在开发模式下运行此查询,环境应为您提供所需的xml片段


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

您是否为所有这些字段创建了跨{祖先、美发师键、时隙、长度}的多属性索引和单属性索引?
@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;