Grails上的GORM save()未保存在数据库

时间:2017-11-25 14:43:34

标签: hibernate grails gorm

我有一个需要保存的对象列表,我有这个功能

private saveAll(List<Element> elements){
    for(Element element: elements){
        element.save(flush:true, insert:true)
    }
}

我的元素类(groovy类)如下所示:

@ToString(excludes = 'metaClass,content', includePackage = false, includeNames = false)
class Element {

    Integer id
    MessageSourceType sourceType
    String key
    String valueEN
    String valueDE
    String valueES
    String valueFR
    String valueIT
    String valuePT
    String valueAR
    String valueCMN
    String valueHI
    String valuePL

    static constraints = {
        sourceType nullable: false, blank: false, maxSize: 256
        key nullable: false, blank: false, maxSize: 254, unique:true
        valueEN nullable: true, maxSize: 64000
        valueDE nullable: true, maxSize: 64000
        valueES nullable: true, maxSize: 64000
        valueFR nullable: true, maxSize: 64000
        valueIT nullable: true, maxSize: 64000
        valuePT nullable: true, maxSize: 64000
        valueAR nullable: true, maxSize: 64000
        valueCMN nullable: true, maxSize: 64000
        valueHI nullable: true, maxSize: 64000
        valuePL nullable: true, maxSize: 64000
    }

    static mapping = {
        table "element"
        id column: "eId"
        version column: "eVersion"
        sourceType column: "eSourceType"
        valueEN column: "eValueEN"
        valueDE column: "eValueDE"
        valueES column: "eValueES"
        valueFR column: "eValueFR"
        valueIT column: "eValueIT"
        valuePT column: "eValuePT"
        valueAR column: "eValueAR"
        valueCMN column: "eValueCMN"
        valueHI column: "eValueHI"
        valuePL column: "eValuePL"
    }

    @Override
    public boolean equals(Object element){
        if(element != null && element instanceof Element){
            if(this.getKey().equalsIgnoreCase(((Element)element).getKey())){
                return true;
            }
        }
        return false;
    }

}

每次保存我都会得到以下日志:

2017-11-25 16:38:56,787 | TRACE |  | localhost-startStop-1 | org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor | executing insertions
2017-11-25 16:38:56,787 | DEBUG |  | localhost-startStop-1 | org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor | executing identity-insert immediately

但是当我检查数据库中的表时,我发现它是空的,没有反映插入。我不明白为什么不会出现错误,或者为什么数据没有保存在数据库中

请你检查我的代码是否有任何问题(我是一个groovy / grails新手)或指导我为什么会发生这样的行为?

0 个答案:

没有答案