Trebla
Trebla

Reputation: 1172

Grails new Domain object with property map not setting property

EDIT: Per my answer below, this seems fixed by a "grails clean". You bang your head in frustration and you overlook the obvious sometimes.

For some time we've had the following structure of domain objects:

abstract class Company {

String name
...
}

and multiple children similar to the following all with different "owner" objects. Each concrete class has it's own table in the DB.

class CompanyChild extends Company {
static belongsTo = [owner:SomeDomain]
...
}

I'm adding another property to the abstract parent for various reasons, so the parent now looks more like the following (CompanyType is an enum):

abstract class Company {

String name
CompanyType companyType
...
}

This all seems pretty straightforward. Now in company service, somewhere I'm doing this:

log.debug("Saving new company type=$companyType")
def company= new Company(name: 'Acme', companyType: companyType, <other properties here>)
log.debug("company object has type=${company.companyType}")

The log shows...

CompanyService Saving new company type=NONPROFIT
CompanyService company object has type=null

What the heck is happening here? It really seems like ${company.companyType} should not be null.

If I add company.companyType = companyType after the object is created it works, but there's something I'm failing to understand.

Edit: grails version is 2.3.11

Upvotes: 0

Views: 592

Answers (1)

Trebla
Trebla

Reputation: 1172

Sometimes you focus so much on a problem that you don't step back and thing... maybe I need to do a full "grails clean"...

Clean and recompile seems to have been my answer.

Upvotes: 2

Related Questions