0

使用具有以下版本的 Grails:

APPLICATION STATUS
App version: 0.1
Grails version: 2.3.5
Groovy version: 2.1.9
JVM version: 1.7.0_51
Reloading active: true
Controllers: 15
Domains: 18
Services: 2
Tag Libraries: 13

我有一个要遵循的域模型。我在编程之前在 MySQL 中构建了表。
在模型中,我有以多对多关系绑定到人(Persons)的 Insertion_orders。此关系由 Insertion_orders_persons 定义,person_id 和 location_id 定义 Insertion_orders_persons 中的条目。此外,还有一个类型值是 ENUMed,可以是 Trafficker、Advertiser、Agency 或(或)Salesperson。一个(或多个)贩运者总是会出现,但其余的可能、可能不存在或具有许多此类关联。我正在尝试根据类型将它们绑定到 Insertion_orders 模型:

package cms


class Insertion_orders {
    String insertion_order_name
    String po_number
    String notes
    String toString() {
        "${insertion_order_name} - ${id}"
    }

    static hasMany = [trafficker: Insertion_orders_traffickers, salesperson: Insertion_orders_salespersons]

    static constraints = {
        insertion_order_name(blank:false)
        po_number()
        notes(widget: 'textarea', nullable:true)
    }
    static mapping ={
        version false
        id column: 'insertion_order_id'
        notes sqlType: 'text'
    }
}

我正在尝试使用继承和鉴别器值来实现这一点。

package cms

class Insertion_orders_persons {
    Persons person
    Insertion_orders insertion_order
    Type type
    String toString() {
        "${person}: ${type}"
    }

    enum Type {
        Trafficker, Salesperson, Advertiser, Agency
    }

    static constraints = {
    }
    static mapping = {
        version false
        id column: 'insertion_order_person_id'
        discriminator column: "type"        
    }

}

class Insertion_orders_traffickers extends Insertion_orders_persons {
    static mapping ={
        discriminator value: "Traffickers"
    }
}

class Insertion_orders_salespersons extends Insertion_orders_persons {
    static mapping ={
        discriminator value: "Salesperson"
    }
}

问题是当我尝试加入扩展类时(如在 Insertion_orders 类中的 hasMany 中),Grails 无法启动并生成以下内容:

|Loading Grails 2.3.5
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
..........................................
|Running Grails application
Error |
2014-04-16 11:33:58,693 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing 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 org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
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 org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
    Line | Method
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Caused by 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 org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Caused by MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Error |
Forked Grails VM exited with error

作为附加信息,无论我如何尝试访问子类或子类组合,我都会收到相同的错误。

这似乎是一个非常基本的功能。有人可以告诉我我错过了什么或做错了什么吗?

4

1 回答 1

0

如果您从 Insertion_orders_persons 中删除鉴别器列:“type”并在各自的源文件中定义 Insertion_orders_persons、Insertion_orders_traffickers 和 Insertion_orders_salespersons,我认为您的代码将起作用。

于 2014-04-16T17:08:37.410 回答