Domain to Domain inheritance

66 Views Asked by At

I cant add property to constraints nor mapping to a domain that has been extended my newly created domain.

class Person1 {
    String name

    static constraints = { name nullable : true }

    static mapping = { 
        table  'PERSON'
        name column : 'PERSON_NAME' 
    }
}

class Person2 extends Person1 {
    String address

    static constraints = { address nullable : true }

    static mapping = { 
        address column : 'PERSON_ADD' 
    }
}

Any idea on how to do this properly?

I got an error

Message: ORA-00904: "THIS_"."CLASS": invalid identifier

1

There are 1 best solutions below

1
Jason Heithoff On

Use Groovy Traits instead:

http://docs.groovy-lang.org/next/html/documentation/core-traits.html

trait Person1 {
   String name

   static constraints = { name nullable : true }

   static mapping = { 
       table  'PERSON'
       name column : 'PERSON_NAME' 
   }
}

class Person2 implements Person1 {
    String address

    static constraints = { address nullable : true }

    static mapping = { 
        name address : 'PERSON_ADD' 
    }
}