tags:

views:

320

answers:

2

Any ideas as to why I'd be getting this error:

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

From this code:

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])
    }
}
A: 

You might have been passing id as part of the params, and a product with that id probably already exists in database.

Langali
Nope. The params don't include a product id and the id it gives in the error doesn't exist in the DB until after the form is submitted. It's as though it's trying to insert it twice.
Thody
Can you try flush: true, just in case!
Langali
+2  A: 

It turned out the problem was a bug with the Searchable plugin, which doesn't allow you to index more than one domain. Disabling Searchable in all but one domain class resolved the issue.

This issue is detailed in an issue on Jira here: http://jira.codehaus.org/browse/GRAILSPLUGINS-601

Thody