我在 Grails 中创建了域,以专注于我们流程背后的业务逻辑。在某些情况下,这会转化为 GORM 生成的超过 Oracle 限制的反向引用并生成“ORA-00972:标识符太长”错误。我能够使用该static mapping
块来重新映射长表名,但我不知道如何为生成的反向引用做同样的事情。
在不暴露任何公司机密信息的情况下,以下示例说明了该问题。
class UnfortunatelyLongClassName {
static mapping = {
table "long_class" // This works great!
}
List<Part> parts
static hasMany = [parts:Part]
}
class Part {
String name
// This generates UNFORTUNATELY_LONG_CLASS_NAME_ID and causes the error
static belongsTo = [UnfortunatelyLongClassName]
}
生成的表的粗略 DDL...
LONG_CLASS (
ID number(19, 0) not null,
VERSION number(19, 0) not null,
primary key (id),
);
PART (
ID number(19, 0) not null,
VERSION number(19, 0) not null,
NAME varchar2(255),
PARTS_IDX number(10, 0),
UNFORTUNATELY_LONG_CLASS_NAME_ID number(19, 0) not null,
primary key (id),
foreign key FK589895C372DB95A (UNFORTUNATELY_LONG_CLASS_NAME_ID) references UNFORTUNATELY_LONG_CLASS_NAME(ID)
);
是否有任何静态映射命令或其他 Grails/GORM 技巧来创建更短的标识符?
如果我使用以下...
static belongsTo = [unfortunatelyLongClassName:UnfortunatelyLongClassName]
static mapping = {
unfortunatelyLongClassName column:"ulcn_id"
}
我收到以下错误...
| Error 2012-07-24 17:53:49,060 [pool-7-thread-1] ERROR context.ContextLoader - Context initialization failed
Message: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [unfortunatelyLongClassName] for class [class mycompany.myproject.mypackage.Part]
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
Caused by InvalidPropertyException: No property found for name [unfortunatelyLongClassName] for class [class mycompany.myproject.mypackage.Part]
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
| Error 2012-07-24 17:53:49,094 [pool-7-thread-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [unfortunatelyLongClassName] for class [class mycompany.myproject.mypackage.Part]
Message: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [unfortunatelyLongClassName] for class [class mycompany.myproject.mypackage.Part]
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread
Caused by InvalidPropertyException: No property found for name [unfortunatelyLongClassName] for class [class mycompany.myproject.mypackage.Part]
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . in java.lang.Thread