GORM Composite映射不起作用

时间:2015-01-12 14:46:51

标签: grails gorm composite-key

在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

发生了什么事?我做错了什么?

1 个答案:

答案 0 :(得分:0)

不确定,消息的含义是什么,但这是错误的:

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']
  }
 }