gpt4 book ai didi

grails - GORM复合映射不起作用

转载 作者:行者123 更新时间:2023-12-02 16:03:21 26 4
gpt4 key购买 nike

在grails 2.4.3和postgresql作为数据库上,我有:

class ClassA {
Set classB = []

static belongsTo = [classC: ClassC]
static hasMany = [classB: ClassB]
}

和:
@EqualsAndHashCode
class ClassB implements Serializable {

ClassA classA
Integer number

static belongsTo = [classA: ClassA]

static mapping = {
id composite: ['number', 'classA']
}

我收到这个奇怪的错误:
[localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializin  
the application: Error creating bean with name 'transactionManagerPostProcessor':
Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting
bean property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory': Invocation of init method failed; nested exception is
java.lang.NullPointerException Message: Error creating bean with name
'transactionManagerPostProcessor': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting
bean property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory': Invocation of init method failed; nested exception is
java.lang.NullPointerException Line | Method ->> 266 | run in
java.util.concurrent.FutureTask - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - | 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor | 617 |
run . . . in java.util.concurrent.ThreadPoolExecutor$Worker ^ 745 | run in
java.lang.Thread

到底是怎么回事?我做错了什么?

最佳答案

不知道消息是什么意思,但这是错误的:

Set ClassB = []

它应该是
Set<ClassB> classB = new HashSet<>()

更新:

参见 the refdoc。这些字段应该是我会说的原始类型。

尝试转换以从ClassB实例中提取属性:
@EqualsAndHashCode
class ClassB implements Serializable {

ClassA classA
String someAProp
Integer number

void setClassA( ClassA a ){
classA = a
someAProp = a.someProp
}

static belongsTo = [classA: ClassA]

static mapping = {
id composite: ['number', 'someAProp']
}
}

关于grails - GORM复合映射不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27904643/

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