Grails/GORM/Hibernate:引用未保存的临时实例的域实例的属性列表
我经常做错事,并在Grails中得到未保存的瞬态实例异常。我不能粘贴代码,如果我粘贴了,你可能会告诉我永远停止编程。但以下是我希望得到一些帮助的一般情况: 我调用Grails/GORM/Hibernate:引用未保存的临时实例的域实例的属性列表,hibernate,grails,gorm,Hibernate,Grails,Gorm,我经常做错事,并在Grails中得到未保存的瞬态实例异常。我不能粘贴代码,如果我粘贴了,你可能会告诉我永远停止编程。但以下是我希望得到一些帮助的一般情况: 我调用instanceOfMyComplicatedDomainClass.save(flush:true,failOnError:true),grails/hibernate为我提供了无处不在的: object references an unsaved transient instance - save the transient ins
instanceOfMyComplicatedDomainClass.save(flush:true,failOnError:true)
,grails/hibernate为我提供了无处不在的:
object references an unsaved transient instance - save the transient instance before flushing: soexample.SomeOtherDomainClass
如果我在同一个类中有几个属性,那么除了理解自己的代码之外,我还能做些什么来确定哪个属性是问题所在?我想在.save()
之前调用一个方法,该方法将println
/log
/无论引起所有愤怒的属性的名称如何。让我举个例子:
class MyComplicatedDomainClass {
SomeOtherDomainClass dataContents
SomeOtherDomainClass moreDataContents
static constraints = {
dataContents(nullable:true)
moreDataContents(nullable:true)
}
}
class SomeOtherDomainClass {
String randomData
}
...
def someRandomMethodAnywhere(){
def newComplicated = new MyComplicatedDomainClass()
def imUnsaved = new SomeOtherDomainClass(randomData:'lalala')
def imOK = new SomeOtherDomainClass(randomData:'lalala2').save()
newComplicated.dataContents = imUnsaved
newComplicated.moreDataContents = imOK
//At this point newComplicated references an unsaved transient, "imUnsaved". If I try to save newComplicated it will fail.
def badPropertyList = findUnsavedTransients(newComplicated)
assert badPropertyList.contains("dataContents") //So findUnsavedTransients method returns a list of the names of the properties referencing the unsaved transients
}
我将如何着手编写findUnsavedTransients?Hibernate中已经有任何方法可以做类似的事情吗
我问的问题与我的另一个问题不同,列出所有未保存的瞬态:
此外,我还看到(并且已经读过)另外15个“Hibernate:未保存的瞬态…”问题,我要求提供一个通用的解决方案,以了解问题所在,而不是针对我在今天的特定片段中所犯错误的具体解决方案。教一个人钓鱼。。。可以这么说。伯特今天发布了一些有趣的消息 www.burtbeckwith.com/blog/?p=1570
签出hibernate侦听器 哇,我真的把标题搞砸了,做了一个很好的SEO perma链接删除Failonerrors并打印domainInstance.errors调用save()后,我一度认为我忽略了一些非常明显的东西,但这是同一条消息,我仍然无法判断是哪个属性出了问题。请尝试会话的
contains()
。