【发布时间】:2012-11-21 04:17:22
【问题描述】:
我的域类有问题。每次我尝试插入条目时都会出现此错误:
The column name "Sequence_No" was not found in this ResultSet.
这是我的域类:
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`'
}
}
但是我试图保存的条目被插入到数据库中,它只是抛出了那个错误。我正在使用 PostgreSQL。我被要求以这种方式命名列名。这就是为什么我需要在命名我的列时放置一个反引号字符,因为如果不这样做,PostgreSQL 会自动将其全部转换为小写字母。每次我删除 id 列中的反引号字符时,错误都不会出现,但显然列名已转换为小写。
【问题讨论】:
-
您在数据源中使用的是 create-drop 还是 update?你检查过数据库架构吗?
-
是的,我在我的数据源中使用 create-drop。我已经检查了架构。似乎错误是由 id 列中的反引号字符引起的,每次我删除列 id 上的反引号时,一切正常。让我感到困惑的是其他带有反引号字符的属性列不会导致任何错误,这与 id 列不同。
标签: hibernate postgresql grails identifier quoting