2017-08-28 65 views
0

最近我已經開始使用Groovy和Grails,但我有以下錯誤:的Groovy/Grails的映射錯誤未知列「類」

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Unknown column 'class' in 'field list' at 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)

但我的實體和它的母親沒有按「T有類屬性 看有沒有一流的領域,但在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 
} 

}

+1

您是否也可以分享'Base'的代碼? – Daniel

+1

何時發生此錯誤? – Roland

回答

0

既然你有一個類層次結構,必須有方法(稱爲雙scriminator)讓ORM知道在從表中獲取行時實例化哪個類。

來自GORM文檔:「在數據庫級別默認情況下,GORM使用帶有稱爲類的鑑別器列的每層表映射,因此父類(Content)及其子類(BlogEntry,Book等)共享相同表。」

請參閱http://gorm.grails.org/6.0.x/hibernate/manual/#inheritanceInGORM