tags:

views:

32

answers:

3

Hi,

in my domain model, I have a method that does something with my data.

e.g.

class Person {

    String lastname
    String firstname

    String bigname() {
        return lastname.toUpperCase()
    }

    static namedQueries = {
        withBigname { name ->
            eq(this.bigname(), name)
        }
    }
}

I want to use this method like a property in the named query, but

this.bigname()
only throws a
java.lang.IncompatibleClassChangeError
-Exception.

Does anyone know how to use domain methods in criteria and named queries?


Update: I now tried this:

class Person {

    String lastname
    String firstname
    String bigname

    static transients = [ 'bigname' ]

    def getBigname() {
        return lastname.toUpperCase()
    }

    static namedQueries = {
        withBigname { name ->
            eq('bigname', name)
        }
    }
}

But it only results in a "could not resolve property: bigname"-exception...

A: 

Try to name the method in JavaBean getter and setter notation. Rename method bigname() to getBigname().

amra
This gives me a "could not resolve property: bigname"...
Jan
A: 

On a static closure, you don't have a this. You'll either need to store the bigname in the Database, do some sort of case insensitive criteria.

Colin Harrington
A: 

looks like you are trying to accomplish this:

class Person {

  String lastname
  String firstname

  static namedQueries = {
      withName { name ->
          eq('lastname', name, [ignoreCase: true])
      }
  }
}
sorry, this was only an example. the real task is far more complex.
Jan