oracle - ORA-00972 : identifier is too long - Best strategy to avoid it in Grails

标签 oracle hibernate grails gorm

保存域类对象时出现“ORA-00972:标识符太长”错误。

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
    }
}

顺便说一句,如果这不是旧数据库,则可以使用以下项目:http://code.google.com/p/hibernate-naming-strategy-for-oracle/

从一开始就生成正确的映射。

关于oracle - ORA-00972 : identifier is too long - Best strategy to avoid it in Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7432501/

相关文章:

hibernate - 使用 GORM/Hibernate 的预加载查询

linux - 为什么创建 Session Factory 需要这么长时间?

grails - 在GSP中导入类的正确方法是什么?

oracle - Hibernate - 按公式属性排序标准

sql - Oracle - Regexp_Like 中的子查询

mysql - SQL 是否保证连接的结果将组合在一起?

java - 具有复合键的一对一

Grails:如何根据格式(JSON、HTML)提供对错误 500 的不同响应?

mysql - Grails:ClassNotFoundException:WAR 部署中的 com.mysql.jdbc.Driver

java - 如何在Hibernate中调用存储过程?