Grails

Data binding with named properties not working correctly in Grails 1.2.0

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.2 final
  • Fix Version/s: 1.2.1
  • Component/s: Persistence
  • Labels:
    None
  • Environment:
    Windows 7 x64, Java SE 1.6u17 (64 bit)

Description

1. Create an Author domain as follows:

class Author {
static hasMany = [books: Book]
String code
String name
static constraints = { code(unique: true, size: 1..10) name(size: 1..40) }
}

2. Create a Book domain as follows:

class Book {
static belongsTo = [author: Author]
String isbn
String title
static constraints = { isbn(unique: true, size: 1..10) title(size: 1..40) }
}

3. Generate the controllers and views for both of the above domains.

4. Run the application and insert two authors.

5. Create one book (it doesn't matter for which author).

6. Without shutting the application down, change the first line of the save method in the book controller from:

def bookInstance = new Book(params)

to:

def bookInstance = new Book()
bookInstance.properties['isbn', 'title', 'author'] = params

7. Try to create a new book. You will get an error of:

DataIntegrityViolationException: not-null property references a null or transient value: Book.author

Additional points of note...

a) If you print the values of the isbn, title and author fields after the attempted data binding, the isbn and title fields are fine but the author field is null (everything is there in the params map, though).

b) If you change the equivalent line in the update method of the book controller from:

bookInstance.properties = params

to:

bookInstance.properties['isbn', 'title', 'author'] = params

and try and change a book's author, the change is ignored.

c) It does not matter whether the domains are placed in packages or not.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: