Search code examples
grailsgrails-orm

how to set value to a null object in grails


I have recently added new field to my table and previous rows will have null value for that field until someone update it.so i tried updating the value by using myobject.findById(1).mynewfield = "data"but its raising an exception saying

Cannot set property 'mynewfield' on null object

i know mynewfield is null for the fetched object but does this mean i cant set some value to an object which was null and if so what should i use to change its value ? here is my code


Solution

  • This message rather tells that myobject.findById(1) is null. Do you have myobject domain class and do you have instance of it with id = 1?

    Double check it.