0

I'm trying to save a domain object with grails 2.3.3 But it is not saved. How can I save it and why is it not saving?

The domain code:

package berg
import nl.jappieklooster.Log

class FieldValue {
    Object value

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

The code that saves:

// 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(".^.^.")
    }
}

The entire value column does not show up in the database

2
  • What's Grails supposed to do with the Object? Serialization is a poor solution in general. Would you expect it to convert things to a byte[]? But then how is it supposed to get the original object back? Commented Dec 10, 2013 at 14:34
  • I tried the byte[] idea, when i read this anwser: stackoverflow.com/questions/1941191/… it could be done with input output streams in the accesors, but its not realy relevant any more, because it was imposible to design an user interface for this design. So we changed it to string. Commented Dec 11, 2013 at 14:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.