Search code examples
hibernategrailsgrails-orm

Grails 2.3.11 - Object failing to persist


I am trying to modify some entities in a service using Grails 2.3.11. I have stripped down to this code:

void updateCompanyType(CompanyType type, Map properties) {
    def role = properties.role?.id ==~ /\d+/ ? Role.get(properties.role.id) : null

    role.name = "Super New Name"
    role.save(failOnError: true, flush: true)

    if (type.role != role) {
        type.role = role
    }

    type.name = properties.name
    type.save(failOnError: true)
}

Type successfully updates, but the role does not. Any insight into why? I know that inside a service call, I'm in a transaction, so I've tried this both with and without the explicit save calls, and that seems to make no difference.

Partial look at the Role class:

class Role implements Comparable {

  Integer id
  String name
  String code
  RoleType roleType

Solution

  • I finally got this to work by setting

    version true

    on my Role domain object in the mapping section.