0

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

  • `name address : 'PERSON_ADD' ` is not valid inside of the `mapping` block. I don't know what your intent was there, but that isn't valid. – Jeff Scott Brown Jan 18 '19 at 16:56
  • Change the constraint in Person2 to `address column: 'PERSON_ADD'` – billjamesdev Jan 18 '19 at 23:19
  • I mean change the mapping. – billjamesdev Jan 19 '19 at 03:31
  • Hi all, sorry for the typo. Its `address column : 'PERSON_ADD' ` . I updated my question. But still i got the same error. Anyway I fix the issue by copying all the properties in Person 1 and put it in in Person 2. Just so you know my real world problem here is that Person1 came from a plugin and I want to add a new property but I can't edit it, so I thought that extending it might be possible. I am just concerned about code re-usability. – John Paul Abiog Feb 06 '19 at 08:15

1 Answers1

0

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' 
    }
}
Jason Heithoff
  • 508
  • 3
  • 10
  • Im sorry, I didn't mention that the Person1 came from plugin. So making it a trait would not be possible because I can't edit it. Anyway, thank you for your reply. :) – John Paul Abiog Feb 06 '19 at 08:17