背景
我正在评估 Grails,因此必须为遗留数据库映射持久层。我从三个表开始:
Clone
- 除其他属性外:主键
id
- 除其他属性外:主键
CloneSet
- 除其他属性外:主键
id
- 除其他属性外:主键
Clone2CloneSet
- 只有两个外键
cloneID
和cloneSetID
- 只有两个外键
域类编码如下:
class Clone {
// among others
static hasMany = [cloneSets: CloneSet]
static mapping = {
id (generator: 'identity')
cloneSets (
joinTable: [name: 'Clone2CloneSet', key: 'cloneID', column: 'cloneSetID'],
cascade: 'none'
)
}
}
class CloneSet {
// among others
static hasMany = [clones: Clone]
static belongsTo = Clone
static mappedBy = [clones: "cloneSets"]
static mapping = {
table (name: 'CloneSet')
id (generator: 'identity')
clones (
joinTable: [name: 'Clone2CloneSet', key: 'cloneSetID', column: 'cloneID'],
cascade: 'none'
)
}
}
问题
Grails 似乎坚持我的连接表的名称是clone2clone_set
:
2013-09-12 10:39:26,459 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - table found: mydatabase.dbo.CloneSet
2013-09-12 10:39:26,459 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - columns: [id, ...]
2013-09-12 10:39:26,465 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - table found: mydatabase.dbo.Clone
2013-09-12 10:39:26,465 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - columns: [id, ...]
2013-09-12 10:39:26,469 [localhost-startStop-1] INFO hbm2ddl.DatabaseMetadata - table not found: clone2clone_set
| Error 2013-09-12 10:39:26,481 [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.HibernateException: Missing table: clone2clone_set
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.HibernateException: Missing table: clone2clone_set
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | 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.HibernateException: Missing table: clone2clone_set
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: clone2clone_set
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by HibernateException: Missing table: clone2clone_set
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
问题
如何说服 Grails 搜索正确的连接表?