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
精彩评论