Row was updated or deleted by another transaction

733 views
Skip to first unread message

Pavel Sergeev

unread,
Nov 17, 2014, 3:28:20 AM11/17/14
to grails-de...@googlegroups.com
Hello, All

I have a domain class:
//////
package admin

class Settings {

static mapping = {
table 'SETTINGS'
version false
//name column : 'PARAMNAME'
value column : 'PARAMVALUE'
description column : 'DESCRIPTION'
id name: 'name', column : 'PARAMNAME'

}
String name;
String value;
String description;

static constraints = {
name maxSize: 150;
value maxSize: 150;
description  maxSize: 1024;
}
}
/////

and I have an empty controller with static scaffold = true
When I am trying to save record a error is happened:
------------------
Class: org.hibernate.StaleObjectStateException
Message: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [admin.Settings#1]
189:				chain.doFilter(request, response);
63:				doFilter(request, response, chain);

Trace

    Line | Method
->>   38 | $tt__save in SettingsController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    189 | doFilter  in PageFragmentCachingFilter.java
|     63 | doFilter  in AbstractFilter.java
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
-----------------

I run my application in a dev mode with default datasource settings:
///
dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
    username = "sa"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
    singleSession = true // configure OSIV singleSession mode
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }
    .....
////

If I change code of domain class:
name column : 'PARAMNAME'
value column : 'PARAMVALUE'
description column : 'DESCRIPTION'
//id name: 'name', column : 'PARAMNAME'

than there is no errors.

What can I do to fix the problem?



Pavel Sergeev

unread,
Nov 17, 2014, 8:28:33 AM11/17/14
to grails-de...@googlegroups.com


What can I do to fix the problem?



UPD 
def mysave() {
def s = new SmsSettings(name: "1", value: "1", description: "1")
s.save(flush: true);
this method of controller gives same error

Mikael Andersson

unread,
Nov 17, 2014, 2:50:13 PM11/17/14
to grails-de...@googlegroups.com
What happens if you get rid of the "column" attribute  in the first example? At a glance it looks like you are referring to a column which is not mapped to the the "name" field.
Ex:
id name: 'name'


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/28cd9f35-ef93-4e18-915b-695e0a818c8d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Pavel Sergeev

unread,
Nov 17, 2014, 11:05:13 PM11/17/14
to grails-de...@googlegroups.com

On Monday, November 17, 2014 11:50:13 PM UTC+4, Mikael Andersson wrote:
What happens if you get rid of the "column" attribute  in the first example? At a glance it looks like you are referring to a column which is not mapped to the the "name" field.
Ex:
id name: 'name'


static mapping = {
table 'SETTINGS'
version false
//name column : 'PARAMNAME'
value column : 'PARAMVALUE'
description column : 'DESCRIPTION'
//id name: 'name', column : 'PARAMNAME'
id name: 'name'

}
This get same error + column 'NAME' instead 'PARAMNAME'.
Perhaps, I didn't understand your thought.
 

Pavel Sergeev

unread,
Nov 19, 2014, 2:36:35 AM11/19/14
to grails-de...@googlegroups.com
RESOLVED:

this is the working code:

static mapping = {
table 'SETTINGS'
version false
name column : 'PARAMNAME'
value column : 'PARAMVALUE'
description column : 'DESCRIPTION'
id name: 'name', generator: 'assigned', type: 'string'
}
but scaffolding doesn't work properly.

Oliver Trieu

unread,
Nov 19, 2014, 8:49:51 AM11/19/14
to grails-de...@googlegroups.com
I recommend against using a custom id column in grails. Like you already saw, scaffolding will run into problems and so will many other things.
We did this to a DomainClass in our Project and we payed the price for this on several occasions. In our case we had a table of countries following the ISO standard and we wanted the country code to be the key. 
Thru the entire project this has caused trouble in various areas so i guess its better to go with the standard id column if possible. 
Reply all
Reply to author
Forward
0 new messages