开发者

Persist List of objects

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
Stri开发者_Go百科ng 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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜