坚持对象列表 [英] Persist List of objects

查看:96
本文介绍了坚持对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个
javax.jdo.JDOFatalUserException:元数据中的错误don.Comment.id:不能有一个java.lang.String主键并且是一个子对象(拥有字段是don.Post.comments)。
NestedThrowables:



运行我的grails + app-engine webapp时



我该如何解决这个问题?

  class Comment.groovy 

import javax.jdo.annotations。*;

@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable =true)
class注释实现Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
字符串标识

@Persistent(mappedBy =comments)
发帖

@Persistent
字符串名

@Persistent
字符串电子邮件

@持续
字符串url

静态约束= {
id(可见:false)
}
}

类Post.groovy
@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable =true)
class Post实现Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id

@Persistent
String title

@Persistent
字符串内容

// static hasMany = [comments:Comment]

@Persistent(defaultFetchGroup =true)
评论评论

静态约束= {
id(visible:false)
}
}


解决方案 div>

对于子类,主键必须是com.google.appengine.api.datastore.Key值(或者编码为字符串),请参阅 http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys


I got this "javax.jdo.JDOFatalUserException: Error in meta-data for don.Comment.id: Cannot have a java.lang.String primary key and be a child object (owning field is don.Post.comments). NestedThrowables:"

when running my grails + app-engine webapp

How can I fix this?

class Comment.groovy

import javax.jdo.annotations.*;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
class Comment implements Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
String id

@Persistent(mappedBy="comments")
Post post

@Persistent
String name

@Persistent
String email

@Persistent
String url

static constraints = {
    id( visible:false)
}
}

class Post.groovy
    @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable="true")
    class Post implements Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id

@Persistent
String title

@Persistent 
String content

//static hasMany = [comments:Comment]

@Persistent(defaultFetchGroup = "true")
Comment comments

static constraints = {
    id( visible:false)
}
}

解决方案

For child classes the primary key has to be a com.google.appengine.api.datastore.Key value (or encoded as a string) see http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys

这篇关于坚持对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆