Grails
  1. Grails
  2. GRAILS-6388

Data-Binding of Domain with Association inside Command Object fails (HibernateException)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor 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.

        Activity

        Hide
        zyro added a comment - - edited

        thanks burt for formatting the code in the description

        Show
        zyro added a comment - - edited thanks burt for formatting the code in the description
        Hide
        Michel Petrovic added a comment -

        Will this issue be really fixed for the release 1.4-M1?

        Show
        Michel Petrovic added a comment - Will this issue be really fixed for the release 1.4-M1?
        Hide
        Graeme Rocher added a comment -

        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.

        Show
        Graeme Rocher added a comment - 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.
        Hide
        Jeff Scott Brown added a comment -

        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.

        Show
        Jeff Scott Brown added a comment - 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.

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            zyro
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development