我对Gorm有一个(对我来说很奇怪)问题。
我们必须清理项目中的一些数据,除了一件事之外的一切都可以正常工作。
这是我们的域类的摘录
class Person {
...
}
class Grade {
...
static hasMany = [speaker: Person]
}
现在我正在搜索要删除的特定人群(重复)。找到它们之后,我需要将待删除人员的所有实例切换到剩余的人。这是该逻辑的摘录:
def personDelete = Person.get(it.get("bhlneuPerson"))
def personBase = Person.get(it.get("bhlPerson"))
...
def grades = Grade.withCriteria {
speaker {
eq("id", personDelete.id)
}
}
grades.each {
it.removeFromSpeaker(personDelete)
it.addToSpeaker(personBase)
it.save(failOnError: true)
}
...
之后我收集了我在列表中找到的所有id并迭代它以删除相应的人
people.each {
def pers = Person.get(it)
if(pers)
pers.delete()
}
但是我收到以下错误:
| Error 2015-09-01 15:02:36,256 [http-bio-8080-exec-15] ERROR errors.GrailsExceptionResolver - ObjectDeletedException occurred when processing request: [GET] /migration/testBHLNEU
deleted object would be re-saved by cascade (remove deleted object from associations): [Person#3970]. Stacktrace follows:
Message: deleted object would be re-saved by cascade (remove deleted object from associations): [Person#3970]; nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [Person#3970]
Line | Method
->> 200 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 49 | doFilter in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [Person#3970]
执行后,仍有一个成绩对象与旧人的身份(#3970),但也是一个新的成绩对象,在上述执行过程中被添加。
我在逻辑中的错在哪里? :)
提前致谢!