持久对象列表

时间:2010-01-14 10:37:43

标签: google-app-engine grails jdo

我得到了这个 “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 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)
}
}

1 个答案:

答案 0 :(得分:2)

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