Search code examples
grails-ormisnullexecutequery

GORM: null check on new property leads to QueryException


I've added a new property uuid into the GORM mapping of the formerly existing domain class BComponent:

static mapping = {
  tablePerHierarchy false
  id column:'bc_id'
  uuid column:'bc_uuid', type:'text'
  name column:'bc_name', type:'text', index:'bc_name_idx'
  normname column:'bc_normname', type:'text', index:'bc_normname_idx'
  version column:'bc_version'
  // ... other properties
}

When it comes to executing code dealing this new property in BootStrap.groovy, like...

BComponent.withTransaction() {
  BComponent.executeQuery("select bc.id from BComponent as bc where bc.uuid is null").each { bc_id ->
    BComponent.withNewTransaction {
      BComponent bc = BComponent.get(bc_id)
      bc.generateUuid()
      bc.save()
      bc.discard()
    }
  }
}

... the following Exception is thrown:

ERROR context.GrailsContextLoaderListener  - Error initializing the application: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]; nested exception is org.hibernate.QueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]; nested exception is org.hibernate.QueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:671)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:414)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:416)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:348)
    ...

Why is that? Is my null check incorrect? I've adopted it from similar checks that work fine, like there is:

BComponent.executeQuery("select bc.id from BComponent as bc where bc.normname is null and bc.name is not null") // ...

Did I forget something? I've already executed

$ grails clean

What else? Thx!


Solution

  • I forgot to add uuid as a property in my Groovy class code. So:

    class BComponent{
      // ...
      String uuid
      // ...
    }
    

    has solved the problem.