使用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,它们以多对多关系绑定到人(人)。此关系由Insertion_orders_persons定义,其中person_id& location_id在Insertion_orders_persons中定义条目。此外,还有一个类型值,包括广告投放人员,广告商,代理商,(或)销售人员。一个(或多个)广告投放人员将始终出现,但其余的可能会,可能没有或有许多这些关联。我试图根据类型将它们绑定到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
作为附加信息,无论我如何尝试访问子类或子类组合,我都会得到相同的错误。
这似乎是一个非常基本的功能。有人可以告诉我我错过了什么或做错了吗?
答案 0 :(得分:0)
如果你从Insertion_orders_persons删除了鉴别器列:“type”并在每个源文件中定义了Insertion_orders_persons,Insertion_orders_traffickers和Insertion_orders_salespersons,我认为你的代码可以正常工作。