开发者

How to store child objects on GAE using JDO from Scala

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜