2011-09-15 35 views
9

Tôi nhận được lỗi "ORA-00972: số nhận dạng quá dài" trong khi lưu đối tượng lớp miền.ORA-00972: số nhận dạng quá dài - Chiến lược tốt nhất để tránh nó trong Grails

Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.intelligrape.model.Address.studentsForPermanentAddressId#79366215] 

Điều gì có thể là giải pháp khả thi để giải quyết vấn đề này ngoại trừ việc giảm độ dài của trường StudentsForPermanentAddressId. Lý do là, đây là một bảng cơ sở dữ liệu kế thừa mà tôi không thể thay đổi.

EDIT: Thêm mô tả lớp miền như yêu cầu của 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 
    } 
} 
+0

Thú vị, giới hạn độ dài của Oracle là 30 và 'studentsForPermanentAddressId'" chỉ "có 29 ký tự. – NullUserException

+0

@NullUserException - Tôi không nghĩ 'studentsForPermanentAddressId' là tên của cột cơ sở dữ liệu thực tế; nó có thể ánh xạ tới một cái gì đó như 'students_for_permanent _...'. –

+0

@Mohd - Bạn có thể cung cấp mã lớp miền xác định mối quan hệ được đề cập không? –

Trả lời

5

Thêm một khối lập bản đồ và các ánh xạ cột hiện có:

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

Là một sang một bên, nếu điều này không phải là một cơ sở dữ liệu kế thừa bạn có thể sử dụng dự án này: http://code.google.com/p/hibernate-naming-strategy-for-oracle/

Để tạo ánh xạ chính xác ngay từ đầu.

Các vấn đề liên quan