GORM 在一个非常简单的 3 个域类情况下感到困惑:对象 - 项目 - 修订。每个项目都有许多修订。正如大师伯特先生所建议的那样,我在这里不使用集合。在我决定制作“项目扩展对象”之前,一切都运行良好。论文是我的领域课程。
class Object {
String title
static mapping = {
tablePerHierarchy false
}
}
class Item {
String name
Object context
static constraints = {
context nullable:true
}
}
class Revision {
Item item
Object context
static constraints = {
context nullable:true
}
}
然后在我的控制器中:
def item = new Item(name:'a-name').save()
def revision = new Revision(item:item).save()
简单——对吧?到目前为止一切正常。
请注意,两个表中的上下文均为空。
现在,让我们让 Revision 扩展 Object,而不更改任何其他内容。
class Revision extends Object {
Item item
Object context
static constraints = {
context nullable:true
}
}
编译好-运行好-但上下文不再为空!context 获得 Revision 的参考!
我做错了什么?GORM 在想什么?谢谢你的帮助。
这是 logSQL:
Hibernate: insert into item (version, context_id, name, parent_id, id) values (?, ?, ?, ?, ?)
TRACE sql.BasicBinder - binding parameter [1] as [BIGINT] - 0
TRACE sql.BasicBinder - binding parameter [2] as [BIGINT] - <null>
TRACE sql.BasicBinder - binding parameter [3] as [VARCHAR] - a-name
TRACE sql.BasicBinder - binding parameter [4] as [BIGINT] - <null>
TRACE sql.BasicBinder - binding parameter [5] as [BIGINT] - 5
Hibernate: insert into object (version, object_type, title, id) values (?, ?, ?, ?)
TRACE sql.BasicBinder - binding parameter [1] as [BIGINT] - 0
TRACE sql.BasicBinder - binding parameter [2] as [VARCHAR] - default-type
TRACE sql.BasicBinder - binding parameter [3] as [VARCHAR] - <null>
TRACE sql.BasicBinder - binding parameter [4] as [BIGINT] - 6
Hibernate: insert into revision (context_id, item_id, id) values (?, ?, ?)
TRACE sql.BasicBinder - binding parameter [1] as [BIGINT] - <null>
TRACE sql.BasicBinder - binding parameter [2] as [BIGINT] - 5
TRACE sql.BasicBinder - binding parameter [3] as [BIGINT] - 6
Hibernate: update item set version=?, context_id=?, name=?, parent_id=? where id=? and version=?
TRACE sql.BasicBinder - binding parameter [1] as [BIGINT] - 1
TRACE sql.BasicBinder - binding parameter [2] as [BIGINT] - 6
TRACE sql.BasicBinder - binding parameter [3] as [VARCHAR] - a-name
TRACE sql.BasicBinder - binding parameter [4] as [BIGINT] - <null>
TRACE sql.BasicBinder - binding parameter [5] as [BIGINT] - 5
TRACE sql.BasicBinder - binding parameter [6] as [BIGINT] - 0