Here's the thing :-) We have two classes, Appointment
and Hairdresser
, both having the same, one ancestor (a static final Key: topParent
) representing the HairSalon
Key. The Appointment
contains the Hairdresser
like this:
@Parent
public Key parent;
public Key hairdresserKey;`
but when we try to filter out the appointment, it doesn't come up with a result. The parent in the hairdresserKey == null
, that might be a clue, but we're kind of stuck now.
So can someone please tell us what's wrong with this query?
Thanks a lot!
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();
To clearify some more, this is how Appointment set up:
@Unindexed
public class Appointment implements 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;
Found this:
This is almost certainly an indexing issue. In order for that query to work, you must define two indexes:
A single-property index on referenceKeyToC A multi-property index on {ancestor, referenceKeyToC} In Objectify 3.x, properties have single-property indexes by default, but if you have added @Unindexed to the class B then you need to put @Indexed on referenceKeyToC. The multi-property index is defined in datastore-indexes.xml. If you run this query in dev mode, the environment should provide you with the snippet of xml needed.
That did the trick! Thanks for pointing in the right direction!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.