似乎无法在 Grails 3 中组合复合 ID
Can't seem to combine composite IDs in Grails 3
我有以下2个域名类
class Foo implements Serializable {
Long fooId1
Long fooId2
Long hFooId1
Long hFooId2
Foo hFoo
Bar bar
static mapping = {
datasources(['ds1','ds2'])
id composite: ["fooId1", "fooId2"]
version false
columns {
bar(insertable: false, updateable: false) {
column name: 'fooId1'
column name: 'fooId2'
}
hFoo(insertable: false, updateable: false) {
column name: 'hFooId1'
column name: 'hFooId2'
}
}
}
static constraints = {
hFooId1 nullable: true
hFooId2 nullable: true
bar nullable: true
hFoo nullable: true
}
}
class Bar implements Serializable
{
Long fooId1
Long fooId2
Foo foo
static mapping = {
datasources(['ds1','ds2'])
id composite: ["fooId1", "fooId2"]
version false
cache include: 'non-lazy'
foo(insertable: false, updateable: false) {
column name: 'fooId1'
column name: 'fooId2'
}
}
}
随着集成测试...
@Integration
@Rollback
@Mock([Foo, Bar])
....
def "Simple Test"(){
expect:
def bar = Bar.build( fooId1: 1, fooId2: 2)
def hFoo = Foo.build( fooId1: 1, fooId2: 2, bar: bar)
def foo = Foo.build( fooId1: 123, fooId2: 456, hFoo: hFoo)
foo.fooId2 == 456
foo.hFoo.fooId2 == 2
foo.bar == null
foo.hFoo.bar.fooId2 == 2
}
我明白了
Cannot treat multi-column property as a single-column property at org.grails.orm.hibernate.cfg.PropertyConfig.checkHasSingleColumn(PropertyConfig.groovy:222) at org.grails.orm.hibernate.cfg.PropertyConfig.getScale(PropertyConfig.groovy:198)
这是一个升级,因此它似乎在 Grails 2 中有效-
谁能看到我错过了什么?
看起来是版本问题....
这适用于 build.gradle
// compile "org.grails.plugins:hibernate4"
或者这个在gradle.properties...
grailsVersion=3.0.11
我有以下2个域名类
class Foo implements Serializable {
Long fooId1
Long fooId2
Long hFooId1
Long hFooId2
Foo hFoo
Bar bar
static mapping = {
datasources(['ds1','ds2'])
id composite: ["fooId1", "fooId2"]
version false
columns {
bar(insertable: false, updateable: false) {
column name: 'fooId1'
column name: 'fooId2'
}
hFoo(insertable: false, updateable: false) {
column name: 'hFooId1'
column name: 'hFooId2'
}
}
}
static constraints = {
hFooId1 nullable: true
hFooId2 nullable: true
bar nullable: true
hFoo nullable: true
}
}
class Bar implements Serializable
{
Long fooId1
Long fooId2
Foo foo
static mapping = {
datasources(['ds1','ds2'])
id composite: ["fooId1", "fooId2"]
version false
cache include: 'non-lazy'
foo(insertable: false, updateable: false) {
column name: 'fooId1'
column name: 'fooId2'
}
}
}
随着集成测试...
@Integration
@Rollback
@Mock([Foo, Bar])
....
def "Simple Test"(){
expect:
def bar = Bar.build( fooId1: 1, fooId2: 2)
def hFoo = Foo.build( fooId1: 1, fooId2: 2, bar: bar)
def foo = Foo.build( fooId1: 123, fooId2: 456, hFoo: hFoo)
foo.fooId2 == 456
foo.hFoo.fooId2 == 2
foo.bar == null
foo.hFoo.bar.fooId2 == 2
}
我明白了
Cannot treat multi-column property as a single-column property at org.grails.orm.hibernate.cfg.PropertyConfig.checkHasSingleColumn(PropertyConfig.groovy:222) at org.grails.orm.hibernate.cfg.PropertyConfig.getScale(PropertyConfig.groovy:198)
这是一个升级,因此它似乎在 Grails 2 中有效-
谁能看到我错过了什么?
看起来是版本问题....
这适用于 build.gradle
// compile "org.grails.plugins:hibernate4"
或者这个在gradle.properties...
grailsVersion=3.0.11