GORMは、非常に単純な3つのドメインクラスの状況で混乱します:オブジェクト-アイテム-リビジョン。各アイテムには多くのリビジョンがあります。マスターのバート氏が提案したように、私はここではコレクションを使用していません。「ItemextendsObject」を作成することを決定するまで、すべてがうまく機能しています。これらは私のドメインクラスです。
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()
シンプルですよね?これまでのところ、すべてが正常に機能しています。
Plzは、両方のテーブルでコンテキストがnullであることに注意してください。
それでは、何も変更せずに、RevisionextendsObjectを作成しましょう。
class Revision extends Object {
Item item
Object context
static constraints = {
context nullable:true
}
}
Okをコンパイルします-Okを実行します-しかし、コンテキストはもうnullではありません!コンテキストはリビジョンへの参照を取得します!
私が間違っていることは何ですか?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