简体   繁体   中英

Grails 2.0.0.M2 - cascade save problem

I have two simple domain classes:

class Name {
 String firstName
 String lastName

 static belongsTo = [person: Person]
}

class Person {
  Name name
  String comment
}

and service with two methods:

class PersonService {
  Person newPerson() {
    def person = new Person()
    person.name = new Name()
    person
  }
  Person savePerson(Person person) {
    person.save()
  }
}

Now if I create a new Person with PersonService.newPerson() and then try to save it using savePerson() method using grails 1.3.7 everything works fine. With grails 1.4.0 or 2.0.0.M2 exception is thrown

Column 'name_id' cannot be null

Is this a bug in new grails? Or maybe there is something wrong with my code?

Test method:

void testPersonSave() {
    def person = personService.newPerson()
    person.name.firstName = 'f'
    person.name.lastName = 'l'
    person.comment = 'comment'

    personService.savePerson(person) //throws an exception
}

Looks like a bug. Please JIRA: http://jira.grails.org/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM