Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Won't Fix
-
Affects Version/s: 2.0.1
-
Fix Version/s: 2.0.2
-
Component/s: Persistence
-
Labels:
-
Environment:Java 1.6 b29, Mac OS X 10.7.3
-
Testcase included:yes
Description
When an invalid versioned domain object is in the session during a flush (explicit or implicit) the version number is bumped but it is not persisted to the database. Then, when it becomes valid again and saved and flushed, hibernate considers it stale, since the version number does not match the version in the database and it throws a StaleObjectStateException.
Example from attached test case:
void "test invalid versioned object in session"() {
def foo = new Foo(name:'valid')
foo.save(failOnError:true, flush:true)
def bar = new Bar(name:'valid')
bar.save(failOnError:true, flush:true)
assert foo.version == 0
bar.name = 'valid2'
foo.name = 'invalid'
bar.save(failOnError:true, flush:true)
assert foo.version == 1
foo.name = 'valid2'
//fails here
foo.save(failOnError:true, flush:true)
}
This is synthetic, but it happens in more complicated normal production code without explicit flushes.
-
Hide
- grails2-invalid-versioned-object-bug-report-21032012.zip
- 21/Mar/12 12:33 PM
- 22 kB
- Michael Cameron
-
- grails-app/.../ApplicationResources.groovy 0.1 kB
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/BuildConfig.groovy 2 kB
- grails-app/conf/Config.groovy 4 kB
- grails-app/conf/DataSource.groovy 1 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/domain/wh/Bar.groovy 0.1 kB
- grails-app/domain/wh/Foo.groovy 0.1 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/.../messages_cs_CZ.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 4 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_sv.properties 3 kB
- grails-app/i18n/messages_th.properties 6 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 0.3 kB
- grails-app/views/index.gsp 3 kB
- grails-app/views/layouts/main.gsp 2 kB
- test/integration/wh/FooTests.groovy 0.6 kB
- application.properties 0.2 kB
Show- grails2-invalid-versioned-object-bug-report-21032012.zip
- 21/Mar/12 12:33 PM
- 22 kB
- Michael Cameron
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Hide
Graeme Rocher
added a comment -
Note it may be the expected Hibernate behavior to increment the version regardless of the operation, although I don't see how
Show
Graeme Rocher
added a comment - Note it may be the expected Hibernate behavior to increment the version regardless of the operation, although I don't see how
Unfortunately this cannot be fixed and appears like a bug in Hibernate and will need a JIRA will need to be raised against Hibernate.
I have committed a test
https://github.com/grails/grails-core/commit/983d6676c469fc2335f9cfa4c9d47504b2789883
The workaround is discard the update by calling foo.discard() and re-apply the changes