Search code examples
javagoogle-app-enginegoogle-cloud-datastoreobjectifydatastore

Google Cloud Objectify - Error saving entity


I want to save an entity and seems to be falling because I am trying to index a HashMap which has a list.

Here are my classes:

**IndicadorEntity **

@Entity
public final class IndicadorEntity {
    private @Index Map<String, List<ObjetivoEntity>> objetivos;
}

ObjetivoEntity

package com.eulen.google.efqm.datastore.entities;

import java.util.Date;

public final class ObjetivoEntity {
    private double objetivo;
    private boolean variable;
    private Date fechaCreacion;
}

When trying to save IndicadorEntity I get the following error:

com.googlecode.objectify.SaveException: Error saving com.eulen.google.efqm.datastore.entities.IndicadorEntity@694e7f0b: objetivos.2: java.util.ArrayList is not a supported property type.

If I remove @Index it works, but I need to know which IndicadorEntity has null objetivos.

Thanks.


Solution

  • There are limits to what the datastore will index. However, you can almost always work around this by creating a synthetic index.

    For example, you can make a field private List<String> myCustomIndex and populate it with an onSave method, filling it with all the things you want to be able to search for. You can extract information from objects at any depth in your object hierarchy.

    Then query on your custom index: filter("myCustomIndex", somevalue)