Google Cloud Objectify – 保存实体时出错

huangapple go评论78阅读模式
英文:

Google Cloud Objectify - Error saving entity

问题

我想保存一个实体,但似乎出现问题,因为我试图索引一个具有列表的 HashMap。

以下是我的类:

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

当尝试保存 IndicadorEntity 时,我遇到以下错误:

com.googlecode.objectify.SaveException: 保存 com.eulen.google.efqm.datastore.entities.IndicadorEntity@694e7f0b 时出错:objetivos.2: java.util.ArrayList 不是受支持的属性类型。

如果我删除 @Index,它可以工作,但我需要知道哪些 IndicadorEntity 具有空的 objetivos。

谢谢。

英文:

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.

答案1

得分: 2

有关数据存储的索引会有一些限制。不过,你几乎总是可以通过创建一个合成索引来解决这个问题。

例如,你可以创建一个字段 private List<String> myCustomIndex,并在一个 onSave 方法中填充它,将所有你想要进行搜索的内容都放入其中。你可以从对象的任何深度提取信息,无论对象层次有多深。

然后在你的自定义索引上进行查询:filter("myCustomIndex", somevalue)

英文:

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)

huangapple
  • 本文由 发表于 2020年5月5日 19:48:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/61612402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定