2009-09-21 117 views
3

任何想法,爲什麼我會收到此錯誤:不同的對象具有相同標識符

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]) 
    } 
} 
+1

需要看你如何呈現的頁面接受初始輸入 – 2009-09-21 17:44:01

+0

該頁面在這一點上是剛剛腳手架代碼的其餘部分。 – Thody 2009-09-23 20:48:25

+0

Product Domain對象的外觀如何? – 2009-10-01 01:22:44

回答

4

原來問題在於Searchable插件存在一個錯誤,它不允許您索引多個域。在除一個域類之外的所有域中禁用可搜索解決了該問題。

這個問題在一個問題上的詳細吉拉的位置:http://jira.codehaus.org/browse/GRAILSPLUGINS-601

+0

這個問題似乎出現在很多不同的環境中。查看http://jira.grails.org/browse/GRAILS-7086?focusedCommentId=63190#comment-63190 http://jira.grails.org/browse/GPSEARCHABLE-35 – 2011-05-15 06:06:18

0

你可能已經被傳遞的id的一部分params,並且具有該id的產品可能已經存在於數據庫中。

+0

沒有。參數不包括產品ID,並且在提交表單之前,錯誤中給出的ID在DB中不存在。就好像它試圖插入兩次。 – Thody 2009-09-23 20:49:58

+0

你可以嘗試flush:true,以防萬一! – Langali 2009-09-24 15:20:18

相關問題