gpt4 book ai didi

hibernate - 似乎无法在Grails 3中组合组合ID

转载 作者:行者123 更新时间:2023-12-02 14:40:44 25 4
gpt4 key购买 nike

我有以下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

关于hibernate - 似乎无法在Grails 3中组合组合ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37263458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com