Hibernate Grails2 level deep belongsTo给出了瞬时实例错误
在圣杯中有可能有2层深的深渊吗?我似乎无法使它在Grails2.2.2中工作 这是我的模型Hibernate Grails2 level deep belongsTo给出了瞬时实例错误,hibernate,grails,gorm,Hibernate,Grails,Gorm,在圣杯中有可能有2层深的深渊吗?我似乎无法使它在Grails2.2.2中工作 这是我的模型 class Content { static constraints = { key(unique: true, blank: false) title(blank: true) } static mapping = { } static hasMany = [elements: Element] String titl
class Content {
static constraints = {
key(unique: true, blank: false)
title(blank: true)
}
static mapping = {
}
static hasMany = [elements: Element]
String title
String key
}
class Element {
static belongsTo = [content: Content]
static constraints = {
textElement(nullable: true)
}
TextElement textElement
}
class TextElement {
static constraints = {
title(nullable: true)
subTitle(nullable: true)
text(blank: false, markdown: true, widget: 'textarea')
}
static belongsTo = [element: Element]
String title
String subTitle
String text
}
在控制器中,我使用以下示例代码绑定并保存
def par = [key: 'akey', title: 'atitle', 'elements[0].textElement.text': 'atext']
def content = new Content(par)
content.save(flush: true)
我得到了一个org.hibernate.TransientObjectException,这让我怀疑在Grails(或hibernate)中是否可以嵌套belongsTo
当然,如果我在保存内容之前先删除一个belongs并保存每个textElement,一切都会正常工作
谢谢 在添加元素时,我会在内容类上使用addTo*,以便自动更新双向引用。检查文档。我不确定这是否有效。元素和TextElement之间的关系不是集合,而是引用。目前,我删除了TextElements:
belongsTo
,并在将内容保存到控制器之前保存它们。
object references an unsaved transient instance - save the transient instance before flushing: TextElement