开发者

Persist List of objects

开发者 https://www.devze.com 2022-12-17 10:29 出处:网络
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).

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

精彩评论

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

关注公众号