【发布时间】:2013-04-09 17:53:31
【问题描述】:
我有一个遗留数据库,我用它来映射 grails 2.2.1 应用程序中的域对象。
我正在使用的表包含 FK 关系返回到它自己的孩子。幸运的是,我知道我只需要在层次结构中深入一层。
T_FOO
----------------------
I LONG
CHILD_FOO LONG
这是可能的结果集:
I CHILD_FOO
- ---------
1 NULL
2 NULL
3 1
4 1
5 2
我的域对象如下所示:
class Foo {
long instanceId
static hasMany = [childFoos: Foo]
static mapping {
table 'T_FOO'
id generator: 'assigned', name: 'instanceId', column: 'I', type: 'long'
version false
autoTimestamp false
instanceId column: 'I'
// I tried joining the table to itself and it didn't work
childFoos joinTable [name: 'T_FOO', key: 'CHILD_FOO', column: 'I'
}
}
查询无效。 Hibernate 将 t0.class 放入选择列表中,但它失败了。
有什么建议吗?
问候, 罗宾
【问题讨论】:
标签: grails grails-orm