Grails投掷非唯一对象异常

时间:2014-06-14 13:37:43

标签: hibernate grails gorm

如何在我的应用程序中多次调用domain.save()?当我在应用程序中途保存域然后在提交应用程序时再次保存它时会抛出非唯一对象异常。我也尝试在提交应用程序之前调用.merge(),但它抛出org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

提前致谢

1 个答案:

答案 0 :(得分:1)

在您的域对象上调用save flush:true并清除会话(请参阅下面的示例)。有关详细信息,请查看此处:grails.org/doc/latest/guide/GORM.html 7.3持久性基础知识

Book.withSession { session ->
   Book book = new Book()
   book.title = 'The Definitive Guide To Grails'
   book.save flush:true
   session.clear()
}