Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Cannot Reproduce
-
Affects Version/s: 1.2.2, 1.3.1
-
Fix Version/s: 2.3-M1
-
Component/s: Persistence
-
Labels:None
-
Environment:win64bit, grails-1.2.2 and 1.3.1
-
Testcase included:yes
Description
test-setup (attached as well):
a) domains (dbt.Author/dbt.Book)
class Author { String name }
class Book { Author author }
b) command object (dbt.BookCommand inside dbt.BookController)
class BookCommand { Book book }
c) controller (scaffolded dbt.BookController)
def update = { BookCommand bc -> [scaffolded update code] }
d) view (scaffolded edit.gsp)
<g:select name="book.author.id" from="${dbt.Author.list()}" optionKey="id" value="${bookInstance?.author?.id}" />
e) bootstrap (BootStrap.groovy)
def a1 = new Author(name: "a1").save() def a2 = new Author(name: "a2").save() def a3 = new Author(name: "a3").save() new Book(author: a1).save() new Book(author: a2).save() new Book(author: a3).save()
--> try to change the author of a book via book/edit:
2010-06-10 14:49:12,623 [http-8080-1] ERROR errors.GrailsExceptionResolver - identifier of an instance of dbt.Author was altered from 1 to 2 org.hibernate.HibernateException: identifier of an instance of dbt.Author was altered from 1 to 2 at $Proxy10.flush(Unknown Source) at dbt.BookController$_closure7.doCall(BookController.groovy:80) at dbt.BookController$_closure7.call(BookController.groovy) at java.lang.Thread.run(Thread.java:619)
this behaviour is fully-automatic executed when using a command object for automatic data-binding.
the same error occurs if you do a manual
def bc = new BookCommand(); bindData(bc, params)
in the controller.
the exception does not only look like theres something wrong, via debugging and various loggings, i could verify that grails does actually try to change the id attribute of the existing related author instead of just changing (in terms of switching) the books author... you can see this, for example, by putting
println Author.list().dump()
as first line of the update action or after a manual bindData call.
i tested only the unidirectional one-to-one scenario.
-
Hide
- dataBindingTest.zip
- 10/Jun/10 8:26 AM
- 183 kB
- zyro
-
- dataBindingTest/.classpath 0.8 kB
- dataBindingTest/.project 0.5 kB
- dataBindingTest/.../com.springsource.sts.grails.core.prefs 0.2 kB
- dataBindingTest/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- dataBindingTest/application.properties 0.2 kB
- dataBindingTest/.../BootStrap.groovy 0.4 kB
- dataBindingTest/.../BuildConfig.groovy 1 kB
- dataBindingTest/grails-app/.../Config.groovy 3 kB
- dataBindingTest/.../DataSource.groovy 0.6 kB
- dataBindingTest/.../UrlMappings.groovy 0.2 kB
- dataBindingTest/.../resources.groovy 0.0 kB
- dataBindingTest/.../BookController.groovy 4 kB
- dataBindingTest/grails-app/.../Author.groovy 0.1 kB
- dataBindingTest/grails-app/.../Book.groovy 0.0 kB
- dataBindingTest/.../messages.properties 3 kB
- dataBindingTest/.../messages_da.properties 3 kB
- dataBindingTest/.../messages_de.properties 4 kB
- dataBindingTest/.../messages_es.properties 3 kB
- dataBindingTest/.../messages_fr.properties 2 kB
- dataBindingTest/.../messages_it.properties 2 kB
- dataBindingTest/.../messages_ja.properties 2 kB
- dataBindingTest/.../messages_nl.properties 3 kB
- dataBindingTest/.../messages_pt_BR.properties 3 kB
- dataBindingTest/.../messages_pt_PT.properties 3 kB
- dataBindingTest/.../messages_ru.properties 4 kB
- dataBindingTest/.../messages_th.properties 5 kB
- dataBindingTest/.../messages_zh_CN.properties 2 kB
- dataBindingTest/grails-app/.../create.gsp 2 kB
- dataBindingTest/grails-app/.../book/edit.gsp 3 kB
- dataBindingTest/grails-app/.../book/list.gsp 2 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
I cannot reproduce the error with the attached example and 2.0, if someone could test 2.0 snapshots and if the issue is still present attach an example. Thank you.
I am closing this issue. If it is reproducible with Grails 2.x, please attach a relevant sample and we can get this addressed in Grails 2.3.
thanks burt for formatting the code in the description