0

我无法使用下面的 JDO Score 类创建多图索引。如果我用 Object[] 代替 Score 一切正常。我认为问题是 Score 类不可序列化?我在 Score 课程中遗漏了什么?

分数等级:

@PersistenceCapable(identityType=IdentityType.APPLICATION, detachable="true")
@javax.jdo.annotations.Version(strategy=VersionStrategy.VERSION_NUMBER,column="VERSION",
     extensions={@Extension(vendorName="datanucleus", key="field-name",value="version")})

public class Score implements Serializable {

  private static final long serialVersionUID = -8805789255398748271L;

  @PrimaryKey
  @Persistent(primaryKey="true", valueStrategy=IdGeneratorStrategy.IDENTITY)
  private Key id;

  private Long version;

  @Persistent
  private String uid;

  @Persistent
  private Integer value;
}

多图索引:

List<Score> rows = new ArrayList(scores);
Multimap<Key, Score> grouped = Multimaps.index(rows,
  new Function<Score, Key>() {

    public Key apply(Score item) {
      return (Key) item.getObjKey();
    }
});
4

1 回答 1

3

首先,如果您要使用 Guava,您可能应该使用真正的 Guava 版本,而不是重新打包以供应用引擎内部使用的代码。

也就是说,看起来(假设重新打包的代码与当前发布的 Guava 代码的工作方式相同)至少有一个Score对象的getObjKey()方法必须返回null. ImmutableMultimaps 不允许null键或值。

于 2011-08-26T03:43:45.453 回答