您可以将列表存储为 EmbeddedProperty。
例如,在这里你有我用于这些需求的通用实用程序类......
import java.util.ArrayList;
import java.util.List;
import com.google.appengine.api.datastore.EmbeddedEntity;
/**
* Utility class for storing Lists of simple objects
* @author toni.navarro
*
*
*
*/
@SuppressWarnings("unchecked")
public class ListTransformer<T> {
public List<T> toList(List<EmbeddedEntity> embeddedList) {
List<T> list = new ArrayList<T>();
if (embeddedList!=null) {
for (EmbeddedEntity embeddedEntity: embeddedList) {
list.add((T) embeddedEntity.getProperty("value"));
}
}
return list;
}
public List<EmbeddedEntity> toEmbeddedList(List<T> list) {
List<EmbeddedEntity> embeddedList = new ArrayList<EmbeddedEntity>();
if (list!=null) {
for (T item: list) {
EmbeddedEntity embeddedItem = new EmbeddedEntity();
embeddedItem.setUnindexedProperty("value", item);
embeddedList.add(embeddedItem);
}
}
return embeddedList;
}
}
...然后将其与以下内容一起使用:
embeddedEntity.setUnindexedProperty("possibleQuestions", new ListTransformer<Long>().toEmbeddedList(turn.getPossibleQuestions()));
... 和:
turn.setPossibleQuestions(new ListTransformer<Long>().toList((List<EmbeddedEntity>)embeddedEntity.getProperty("possibleQuestions")));