这可能是菜鸟的错误,所以请原谅我。我在高处和低处寻找解决方案,但没有结果-因此,我想在此添加第一篇文章:-)
我有两个域类,一个称为Domain,一个称为Page。如下代码所示,域中有许多页面。
class Domain {
...
static hasMany = [ pages : Page, ... ]
static mapping = {
pages lazy:true
}
}
class Page {
String identifier
...
static belongsTo = [ domain : Domain ]
static hasMany = [ ... ]
static constraints = {
identifier(blank:false, unique:'domain')
}
static mapping = {
...
domain lazy:true
}
}
def domain = page.domain
domain.removeFromPages(page);
page.delete()
domain.save(flush:true)
def page = new Page(identifier:'...').save(failOnError:true)
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
最佳答案
我建议考虑对您的类(class)进行重新设计。
首先,从“域”中删除页面集合
Class Domain {
// no pages here
}
Class Page {
String identifier
Domain domain
...
}
https://stackoverflow.com/questions/7020732/