域到域的继承

时间:2019-01-18 11:54:55

标签: inheritance grails gorm grails-2.5

我无法将属性添加到约束中,也无法映射到已扩展为我新创建的域的域。

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' 
    }
}

关于如何正确执行此操作的任何想法?

我遇到错误

消息:ORA-00904:“ THIS _”。“ CLASS”:无效的标识符

1 个答案:

答案 0 :(得分:0)

改为使用Groovy特性:

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' 
    }
}