默认情况下GORM 类使用 table-per-hierarchy 来映射继承的. 这就有一个缺点就是在数据库层面,列不能有 NOT-NULL 的约束。
如果你更喜欢 table-per-subclass 你可以使用下面方法:class Payment {
Long id
Long version
Integer amount
static mapping = {
tablePerHierarchy false
}
}
class CreditCardPayment extends Payment {
String cardNumber
}
在祖先 Payment 类的映射设置中,指定了在所有的子类中,不使用 table-per-hierarchy映射.