如何使用 Scala 中的 JDO 在 GAE 上存储子对象
我在两个类之间有父子关系,但子对象永远不会存储。我确实收到警告:
“org.datanucleus.store.appengine.MetaDataValidator checkForIllegalChildField:无法验证关系 net.vermaas.kivanotify.model.UserCriteria.internalCriteria”,
但我不清楚为什么会发生这种情况。已经尝试了几种替代方案但没有运气。
父类是“UserCriteria”,它有一个“Criteria”列表作为子类。
这些类定义如下(Scala):
class UserCriteria(tu: String, crit: Map[String, String]) extends LogHelper {
@PrimaryKey
@Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
var id = KeyFactory.createKey("UserCriteria", System.nanoTime)
@Persistent
var twitterUser = tu
@Persistent
var internalCriteria: java.util.List[Criteria] = flatten(crit)
def flatten(crits: Map[String, String]) : java.util.List[Criteria] = {
val list = new java.util.ArrayList[Criteria]
for (key <- crits.keySet) {
list.add(new Criteria(this, key, crits(key)))
}
list
}
def criteria: Map[String, String] = {
val crits = mutable.Map.empty[String, String]
for (i <- 0 to internalCriteria.size-1) {
crits(internalCriteria.get(i).name) = internalCriteria.get(i).value
}
Map.empty ++ crits
}
// Stripped the equals, canEquals, hashCode, toString code to keep the code snippet short...
}
@PersistenceCapable
@EmbeddedOnly
class Criteria(uc: UserCriteria, nm: String, vl: String) {
@Persistent
var userCriteria = uc
@Persistent
var name = nm
@Persistent
var value = vl
override def toString = {
"Criteria name: " + name + " value: " + value
}
}
有什么想法为什么不存储子类吗?或者为什么我会收到错误消息?
谢谢, 下吕
I'm have a parent-child relation between 2 classes, but the child objects are never stored. I do get an warning:
"org.datanucleus.store.appengine.MetaDataValidator checkForIllegalChildField: Unable to validate relation net.vermaas.kivanotify.model.UserCriteria.internalCriteria"
but it is unclear to me why this occurs. Already tried several alternatives without luck.
The parent class is "UserCriteria" which has a List of "Criteria" as children.
The classes are defined as follows (Scala):
class UserCriteria(tu: String, crit: Map[String, String]) extends LogHelper {
@PrimaryKey
@Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
var id = KeyFactory.createKey("UserCriteria", System.nanoTime)
@Persistent
var twitterUser = tu
@Persistent
var internalCriteria: java.util.List[Criteria] = flatten(crit)
def flatten(crits: Map[String, String]) : java.util.List[Criteria] = {
val list = new java.util.ArrayList[Criteria]
for (key <- crits.keySet) {
list.add(new Criteria(this, key, crits(key)))
}
list
}
def criteria: Map[String, String] = {
val crits = mutable.Map.empty[String, String]
for (i <- 0 to internalCriteria.size-1) {
crits(internalCriteria.get(i).name) = internalCriteria.get(i).value
}
Map.empty ++ crits
}
// Stripped the equals, canEquals, hashCode, toString code to keep the code snippet short...
}
@PersistenceCapable
@EmbeddedOnly
class Criteria(uc: UserCriteria, nm: String, vl: String) {
@Persistent
var userCriteria = uc
@Persistent
var name = nm
@Persistent
var value = vl
override def toString = {
"Criteria name: " + name + " value: " + value
}
}
Any ideas why the childs are not stored? Or why I get the error message?
Thanks,
Gero
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您似乎正在尝试实现一个拥有的一-一对多关系。另外,您似乎忘记了 UserCriteria 的 internalCriteria 字段的 @Embedded 注释,但我认为它可能仍然无法工作,因为该字段包含一个列表而不是嵌入类本身。
It looks to me like you are trying to implement an owned one-to-many relationship. Also you seem to have forgotten the @Embedded annotation for the UserCriteria's internalCriteria field, though I think, that it might still not work since the field contains a list and not the embedded class itself.