为什么 JDO 类会破坏 Guava MultiMap 索引?
我无法使用下面的 JDO Score 类创建多重映射索引。如果我用 Object[] 代替 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();
}
});
I'm unable to create a multimap index with the JDO Score class below. If I substitute Object[] for Score everything works fine. I thought the issue was that the Score class was not serializable? What am I missing from the Score class?
Score Class:
@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;
}
Multimap index:
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();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您要使用 Guava,您可能应该使用 Guava 的真实版本,而不是重新打包供应用程序引擎内部使用的代码。
也就是说,看起来(假设重新打包的代码与当前发布的 Guava 代码的工作方式相同)至少有一个
Score
对象的getObjKey()
方法必须返回空
。ImmutableMultimap
不允许使用null
键或值。First of all, if you're going to use Guava you should probably use a real release of Guava rather than code that's repackaged for internal use in app engine.
That said, it looks like (assuming the repackaged code works the same as the current released Guava code) at least one of your
Score
objects'getObjKey()
method must be returningnull
.ImmutableMultimap
s don't allownull
keys or values.