【问题标题】:ORA-00972: identifier is too long - Best strategy to avoid it in GrailsORA-00972: 标识符太长 - 在 Grails 中避免它的最佳策略
【发布时间】:2011-11-17 22:49:23
【问题描述】:

我在保存域类对象时收到“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
    }
}

【问题讨论】:

  • 有意思,Oracle 的长度限制是 30,而studentsForPermanentAddressId "only" 有 29 个字符。
  • @NullUserException - 我不认为studentsForPermanentAddressId 是实际数据库列的名称;它可能映射到 students_for_permanent_... 之类的东西。
  • @Mohd - 您能否提供定义相关关系的域类代码?
  • 伙计们,我已经通过 grails 邮件列表得到了这个问题的答案。请检查。 grails.1312388.n4.nabble.com/…
  • NullUser,Hibernate 有时会生成带有一些非常丑陋的连接和别名的 sql,所以如果你是 29 岁,30 岁时生成别名并不难,所以即使他使用默认命名和列名是studentsForPermanentAddressId,例如可以生成带有_studentsForPermanentAddressId0的sql。

标签: oracle hibernate grails grails-orm


【解决方案1】:

添加一个映射块和现有的列映射:

    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/

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

【讨论】:

    猜你喜欢
    • 2012-12-22
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 2011-02-16
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多