最近我开始使用Groovy和Grails但是我遇到以下错误:
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
“字段列表”中的未知列“类” 在com.mysql.jdbc.Util.handleNewInstance(Util.java:404) 在com.mysql.jdbc.Util.getInstance(Util.java:387) 在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
但是我的实体及其母亲没有类属性 看到没有类字段,但在MySQL插入它的当前
class Freight extends Base {
String codeBegin
String codeEnd
BigDecimal weight
BigDecimal value
BigDecimal minValue
FreightRange range
Integer time
FreightType type
String name
Integer leadTime
BigDecimal realFreightValue
String realFreightName
FreightType realFreightType
Manufacturer manufacturer
static embedded = ['range']
static transients = ['type', 'name', 'leadTime', 'realFreightValue', 'realFreightName', 'realFreightType', 'manufacturer']
static belongsTo = [partnerFreightType: PartnerFreightType]
static mapping = {
version false
}
static constraints = {
codeBegin nullable: true, blank: true, validator: Freight.rangeValidator
codeEnd nullable: true, blank: true, validator: Freight.rangeValidator
weight nullable: false, min: BigDecimal.valueOf(0.001)
value nullable: false, min: BigDecimal.valueOf(0), max: BigDecimal.valueOf(9999.99)
minValue nullable: false, min: BigDecimal.valueOf(0)
range nullable: true
time nullable: true
}
static rangeValidator = { val, obj ->
if (obj.codeBegin?.replace('-', '')?.toInteger() > obj.codeEnd?.replace('-', '')?.toInteger())
return 'freight.error.range'
}
String getHash() {
(this.partnerFreightType + this.type + this.value).encodeAsMD5()
}
void useRange(FreightRange range) {
this.range = range
def codes = range.codes()
this.codeBegin = codes.min
this.codeEnd = codes.max
}
}
答案 0 :(得分:0)
由于你有一个类层次结构,因此ORM必须有方法(称为鉴别器)才能知道从表中获取行时要实例化的类。
来自GORM文档:“在数据库级别,GORM默认使用每层次表映射与一个名为class的鉴别器列,因此父类(Content)及其子类(BlogEntry,Book等)共享同一个表。“
请参阅http://gorm.grails.org/6.0.x/hibernate/manual/#inheritanceInGORM