最近,我已经开始使用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上插入它的存在
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
}}
发布于 2017-08-29 20:39:18
因为您有一个类层次结构,所以ORM必须有方法(称为区分器)来知道在从您的表中获取行时要实例化哪个类。
GORM文档:“在数据库级别,GORM默认使用表-每个层次结构映射和一个名为class的判别器列,因此父类(内容)及其子类(BlogEntry、Book等)共享相同的表。”
请参阅http://gorm.grails.org/6.0.x/hibernate/manual/#inheritanceInGORM
https://stackoverflow.com/questions/45923954
复制相似问题