保存域类对象时出现“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/

10-12 15:51