具有相同标识符的不同对象

时间:2009-09-21 16:19:45

标签: grails

关于我为什么会收到此错误的任何想法:

nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [Product#6]

从这段代码:

def save = {    
    def productInstance = new Product(params)

    if(!productInstance.hasErrors() && productInstance.save()) {
        flash.message = "Product ${productInstance.id} created"
        redirect(action:show,id:productInstance.id)
    }
    else {
        render(view:'create',model:[productInstance:productInstance])
    }
}

2 个答案:

答案 0 :(得分:4)

事实证明问题是Searchable插件的一个错误,它不允许您索引多个域。在除一个域类之外的所有域中禁用可搜索解决了该问题。

此问题详见Jira上的问题:http://jira.codehaus.org/browse/GRAILSPLUGINS-601

答案 1 :(得分:0)

您可能已将id作为params的一部分传递,并且具有该ID的产品可能已存在于数据库中。