Grails域类继承--GORM设置错误的外键

时间:2013-02-11 04:15:09

标签: hibernate inheritance gorm grails-2.0

GORM在一个非常简单的3域类情况中感到困惑:对象 - 项目 - 修订。每个项目都有很多修订。正如伯特先生所说,我不是在这里使用收藏品。一切顺利,直到我决定制作“Item extends Object”。这些是我的域类。

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()

简单 - 对吗?到目前为止一切正常。

请注意, context 在两个表中均为空。

现在,让我们使Revision扩展Object,而不做任何改动。

class Revision extends Object {
  Item item
  Object context
  static constraints = {
    context nullable:true
    }
  }

编译好 - 运行确定 - 但上下文不再为空了! 上下文获取修订的参考号。

我做错了什么? 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

0 个答案:

没有答案