简体   繁体   中英

Grails naming id column Error

I'm having a problem in my domain class. Every time I try to insert an entry this error appears:

The column name "Sequence_No" was not found in this ResultSet.

Here is my domain class:

class Record {

String firstName
String middleName
String lastName
String motherMaidenLastName
String motherMaidenMiddleName
Date birthDate
String examTypeCode
Date examinationDate

static constraints = {
    firstName nullable:false, blank:false, maxSize: 50
    middleName nullable:true, blank:true, maxSize: 50
    lastName nullable:false, blank:false, maxSize: 50
    motherMaidenLastName nullable:true, blank:true, maxSize: 50
    motherMaidenMiddleName nullable:true, blank:true, maxSize: 50
    birthDate  nullable: false
    examTypeCode  nullable: false, maxSize: 4
    examinationDate  nullable: false
}

static mapping  = {
    datasource 'oevs'
    table '`elig`'
    id column: '`Sequence_No`'
    firstName column: '`FirstName`'
    middleName column: '`MiddleName`'
    lastName column: '`LastName`'
    motherMaidenLastName column: '`MotherMaidenLastName`'
    motherMaidenMiddleName column: '`MotherMaidenMiddleName`'
    birthDate column: '`Date_Birth`'
    examTypeCode column: '`ExamType`'
    examinationDate column: '`Date_Exam`'
    }
}

But the entry I tried to save is inserted in the database, it just throws that error. I'm using PostgreSQL. I was required to name the column names that way. That's why I need to place a back tick character in naming my columns because PostgreSQL automatically converts it all to lowercase letters if don't do that. Every time I remove the backtick character in my id column, the error doesn't show up but obviously the column name was converted to lowercase.

The error lies in this statement:

That's why I need to place a back tick character in naming my columns because PostgreSQL automatically converts it all to lowercase letters if don't do that.

Backticks (``) are used in MySQL only (in pointless violation of the SQL standard - you can use SET sql_mode = 'ANSI'; to fix this). Backticks have no special meaning to PostgreSQL or in standard SQL. Use double-quotes( "" ) in PostgreSQL (are anywhere, really) to achieve what you are aiming for. More details in this related answer .

You almost had it right: identifiers that are not double-quoted are cast to lower-case in PostgreSQL. Read the chapter Identifiers and Key Words in the manual for details.

I generally advice not to use CamelCase identifiers in PostgreSQL at all. There is many ways to trip over that. Desperate questions of confused users keep popping up here. Don't use CamelCase and never double-quote identifiers if you can. Once you create a non-standard identifier you have to double-quote that at all times ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM