grails删除不是持久的
我试图从我的数据库中删除一个更复杂的相关对象,因此我使用grails控制台进行了调查,并得出以下结论:grails删除不是持久的,grails,gorm,Grails,Gorm,我试图从我的数据库中删除一个更复杂的相关对象,因此我使用grails控制台进行了调查,并得出以下结论: TextContent textContent = ...The item to delete... // TextContent hasMany BundleText // BundleText belongsTo BundleVersion textContent.bundleTexts.ea
TextContent textContent = ...The item to delete...
// TextContent hasMany BundleText
// BundleText belongsTo BundleVersion
textContent.bundleTexts.each {
BundleVersion bundleVersion = it.bundleVersion
bundleVersion.removeFromBundleTexts(it)
textContent.removeFromBundleTexts(it)
it.delete()
//bundleVersion.save()
}
// Language hasMany TextContent
// Language belongsTo textContent (?)
textContent.language.removeFromTextContents(textContent)
// TextContent belongsTo textCode
TextCode textCode = textContent.textCode
textCode.removeFromTextContents(textContent)
textContent.delete()
//textCode.save()
现在,所有这些都可以在grails控制台中正常工作,因此我将其放在数据库服务中,并运行该应用程序。
应用程序成功地运行了该方法(已验证),但当它重新读取集合时,该方法会再次出现。。
大谜团
有人见过类似的东西吗?还是我太天真了
编辑
请澄清:
class TextCode {
static hasMany = [ textContents : TextContent ]
}
class TextContent {
Language language
static belongsTo = [ textCode : TextCode ]
static hasMany = [ bundleTexts : BundleText]
}
class BundleText {
TextContent textContent
static belongsTo = [ bundleVersion : BundleVersion ]
}
class Language {
static hasMany = [ textContents : TextContent ]
}
您是否尝试过使用flush:true命令GORM将更改持久化回数据库。如下图所示
def book = Book.get(1)
book.delete(flush: true)
flush:true是您所需要的全部技巧,或者您应该修改节上datasource.groovy的配置
dbCreate
像这样说
dbUpdate
您是否尝试过使用flush:true命令GORM将更改持久化回数据库。如下图所示
def book = Book.get(1)
book.delete(flush: true)
flush:true是您所需要的全部技巧,或者您应该修改节上datasource.groovy的配置
dbCreate
像这样说
dbUpdate
不知道为什么上面的方法不起作用,但我设法用直接HQL解决了它
BundleText.executeUpdate("delete BundleText bt where bt.textContent=:content", [content: textContent])
TextContent.executeUpdate("delete TextContent tc where tc.id = :id", [id: textContent.id])
不知道为什么上面的方法不起作用,但我设法用直接HQL解决了它
BundleText.executeUpdate("delete BundleText bt where bt.textContent=:content", [content: textContent])
TextContent.executeUpdate("delete TextContent tc where tc.id = :id", [id: textContent.id])
是的,它冲洗它没有任何问题。使用控制台时,它可以正常工作并保持良好状态。它在应用程序中“起作用”,除了删除没有持久化。@NielsBechNielsen我不明白你的想法,它在控制台中起作用,或者你的意思是(GroovyConsole)?运行“grails控制台”,你就可以在grails应用程序预加载的情况下获得交互式控制台。。是的,它可以毫无问题地刷新它。使用控制台时,它可以正常工作并保持良好状态。它在应用程序中“起作用”,只是删除没有持久化。@NielsBechNielsen我不明白你的想法,它在控制台中起作用,或者你的意思是(GroovyConsole)?运行“grails控制台”,你就可以在grails应用程序预加载的情况下获得交互式控制台。。显示你域的代码TextCode,TextContent,和BundleVersion显示域TextCode、TextContent和BundleVersion的代码