使用属性类型对象保存grails域对象失败

时间:2013-12-10 11:07:15

标签: spring hibernate grails groovy

我正在尝试使用grails 2.3.3保存域对象但是它没有保存。如何保存它,为什么不保存?

域代码:

package berg
import nl.jappieklooster.Log

class FieldValue {
    Object value

    public String toString(){
        Log.debug "Field value: {0}", value
        return value.toString()
    }  
    static constraints = {
    }  
}

保存的代码:

// an extract from the bootsrap file
def init = { servletContext ->
    def blueFV = new FieldValue(value: Color.blue)        
    def smallFV = new FieldValue(value: "small")
    def fieldVals = [blueFV, smallFV]
    saveData(fieldVals,berg.FieldValue)
}
public void saveData(List list, Class type){
    def wholeList = type.list() ?: []

    println("Started with adding the "+type.getName()+" classes.")

    int saved = 0;
    int failed = 0;

    if(!wholeList){
        list.each{ i ->
            if(i.validate()){
                i.save(flush:true, failOnError: true)
                saved++
            }
            else{
                println("! - - - Warning: '"+i.toString()+"' could not be created! - - - !")
                failed++
            }
        }
        if(failed > 0)//if one fails, let the message appear more clearly
            println(".v.v.")
        println("When saving the "+type.getName()+" classes: "+saved+" were saved, "+failed+" failed to be saved.")
        if(failed > 0)
            println(".^.^.")
    }
}

整个值列未显示在数据库中

0 个答案:

没有答案