gpt4 book ai didi

mysql - GRAILS:使用域子类

转载 作者:行者123 更新时间:2023-11-30 00:22:30 25 4
gpt4 key购买 nike

使用具有以下版本的 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 中构建了表。
在模型中,我有 Insertion_orders 与多对多关系中的人 (Persons) 绑定(bind)。此关系由 Insertion_orders_persons 定义,其中 person_id 和 location_id 定义 Insertion_orders_persons 中的条目。此外,还有一个类型值,可枚举为广告转换人员、广告商、代理机构或销售人员。一个(或多个)贩运者总会出现,但其余的可能会出现,也可能不会出现,或者有很多这样的关联。我正在尝试根据 Insertion_orders 模型的类型将它们绑定(bind):

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

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

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

最佳答案

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

关于mysql - GRAILS:使用域子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23114106/

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