【发布时间】:2021-04-30 00:34:04
【问题描述】:
这是我的抽象类:
package mypackage.commons
abstract class Content {
String name
static constraints = {
name nullable: false, blank: false, size: 1..50
}
}
这是我的扩展类:
package mypackage.project
import mypackage.commons.Content
class Plane extends Content {
String something;
}
这是我的 Bootstrap.groovy 文件:
package mypackage
import mypackage.commons.Content
import mypackage.project.Plane
class BootStrap {
def init = { servletContext ->
Plane boing1 = new Plane (name: 'Boing', something: 'Hello').save()
Plane boing2 = new Plane (name: 'Boing', something: 'Goodbye').save()
}
def destroy = {
}
}
问题是当我在 MySQL 上,当我使用 SHOW TABLES 时,我只能看到 content plane。
这里是SELECT * FROM content;
的内容+----+---------+-------+-------------------------+-----------+
| id | version | name | class | something |
+----+---------+-------+-------------------------+-----------+
| 1 | 0 | Boing | mypackage.project.Plane | Hello |
| 2 | 0 | Boing | mypackage.project.Plane | Goodbye |
+----+---------+-------+-------------------------+-----------+
编辑
测试迈克的答案后:
package mypackage.commons
abstract class Content {
String name
static constraints = {
name nullable: false, blank: false, size: 1..50
}
static mapping = {
tablePerHierarchy false
}
}
这是SHOW TABLES
的结果+-----------------------+
| Tables_in_my_database |
+-----------------------+
| content |
| plane |
+-----------------------+
这是 SELECT * FROM content 的结果:
+----+---------+-------+
| id | version | name |
+----+---------+-------+
| 1 | 0 | Boing |
| 2 | 0 | Boing |
+----+---------+-------+
这是 SELECT * FROM plane 的结果:
+----+------------+
| id | something |
+----+------------+
| 1 | Hello |
| 2 | Goodbye |
+----+------------+
编辑结束
预期行为:
SHOW TABLES; 应该只显示表格 plane
SELECT * FROM plane 应该告诉我这个:
+----+---------+-------+------------+
| id | version | name | something |
+----+---------+-------+------------+
| 1 | 0 | Boing | Hello |
| 2 | 0 | Boing | Goodbye |
+----+---------+-------+------------+
我怎样才能得到预期的结果?
有可能吗?
提前致谢。
【问题讨论】:
标签: mysql grails grails-orm abstract extends