Oracle ORA-00972:标识符太长-在Grails中避免它的最佳策略
保存域类对象时出现“ORA-00972:标识符太长”错误Oracle ORA-00972:标识符太长-在Grails中避免它的最佳策略,oracle,hibernate,grails,gorm,Oracle,Hibernate,Grails,Gorm,保存域类对象时出现“ORA-00972:标识符太长”错误 Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.intelligrape.model.Address.studentsForPermanentAddressId#79366215] 除了减少studentsForPermanentAddressId字段的长度外,还有什么可能的解决方案可以解决这个
Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.intelligrape.model.Address.studentsForPermanentAddressId#79366215]
除了减少studentsForPermanentAddressId字段的长度外,还有什么可能的解决方案可以解决这个问题呢。原因是,这是一个我无法更改的遗留数据库表
编辑:根据Rob Hruska的要求添加了域类描述
package com.intelligrape.model
class Address {
String address1
String address2
String boxNumber
String city
Long stateLid
String province
String zipCode
Long countryLid
Double latitude
Double longitude
Long radius
static hasMany = [studentsForPermanentAddressId: Student, studentsForLocalAddressId: Student]
static constraints = {
address1 nullable: true
address2 nullable: true
boxNumber nullable: true, size: 1..25
city nullable: true, size: 1..30
stateLid nullable: true
province nullable: true, size: 1..64
zipCode nullable: true, size: 1..15
countryLid nullable: true
latitude nullable: true
longitude nullable: true
radius nullable: true
studentsForPermanentAddressId nullable: true
studentsForLocalAddressId nullable: true
}
}
添加映射块和现有列映射:
package com.intelligrape.model
class Address {
String address1
String address2
String boxNumber
String city
Long stateLid
String province
String zipCode
Long countryLid
Double latitude
Double longitude
Long radius
static hasMany = [studentsForPermanentAddressId: Student, studentsForLocalAddressId: Student]
static mappings = {
studentsForPermanentAddressId(column: 'stud_perm_addr_id')
}
static constraints = {
address1 nullable: true
address2 nullable: true
boxNumber nullable: true, size: 1..25
city nullable: true, size: 1..30
stateLid nullable: true
province nullable: true, size: 1..64
zipCode nullable: true, size: 1..15
countryLid nullable: true
latitude nullable: true
longitude nullable: true
radius nullable: true
studentsForPermanentAddressId nullable: true
studentsForLocalAddressId nullable: true
}
}
另外,如果这不是遗留数据库,您可以使用此项目:
从一开始就生成正确的映射。这很有趣,Oracle的长度限制是30,并且
studentsForPermanentAddressId
“only”有29个字符。@NullUserException-我不认为studentsForPermanentAddressId
是实际数据库列的名称;它可能映射到了类似于students\u for\u permanent\u…
@Mohd的东西-你能提供定义所讨论的关系的域类代码吗?伙计们,我通过grails邮件列表找到了这个问题的答案。请查收。NullUser,Hibernate有时会生成带有一些非常难看的联接和别名的sql,因此,如果您是29岁,30岁,则生成别名并不难,因此,即使他使用默认命名,并且列名为StudentsForPermantAddressId,它也可以生成带有_StudentsForPermantAddressID0的sql。