首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Groovy/Grails映射错误“字段列表”中未知列“class”

问Groovy/Grails映射错误“字段列表”中未知列“class”
EN

Stack Overflow用户
提问于 2017-08-28 16:57:06
回答 1查看 629关注 0票数 0

最近,我已经开始使用Groovy和Grails,但是我遇到了以下错误:

由: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:引起 “字段列表”中未知列'class‘在com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at com.mysql.jdbc.Util.getInstance(Util.java:387) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)

但是我的实体和它的母亲没有class属性,没有类字段,但是在MySQL上插入它的存在

代码语言:javascript
复制
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
}

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-29 20:39:18

因为您有一个类层次结构,所以ORM必须有方法(称为区分器)来知道在从您的表中获取行时要实例化哪个类。

GORM文档:“在数据库级别,GORM默认使用表-每个层次结构映射和一个名为class的判别器列,因此父类(内容)及其子类(BlogEntry、Book等)共享相同的表。”

请参阅http://gorm.grails.org/6.0.x/hibernate/manual/#inheritanceInGORM

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45923954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档