持久化对象列表
我得到了这个 “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)
}
}
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)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于子类,主键必须是 com.google.appengine.api.datastore.Key 值(或编码为字符串),请参阅 http://code.google.com/appengine/docs/java/datastore/creatinggettinganddeletingdata.html#Keys
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