开发者

Grails: Property Null error

I've a domain called Modulo with some properties and a Controller with a method that create a object from model and save it, when execute save the shell show this error:

  • La propiedad [{0}] de la clase [{1}] no puede ser nulo

But if i set the constraint nullable to true, the error show again. I think that i should not set this cosntraint.

The model is linked to a mysql table with all properties except id allow null.

I think I am not doing something wrong here. Any advice??

Domain: Modulo

class Modulo {
    String nombre
    String icon
    String url




//static constraint = {
  //    url(nullable:true)
  //}

  }

Controller: Example

class ExampleController {
    def index = { 
       def modulo = new Modulo(
         nombre:'xxx',
         icon:'xxx'
        )

        if (modulo.save()){
          println 'ok'
        }else{
          modulo.errors.allErrors.each { println it.defaultMessage}
        }
    }
}

T开发者_开发问答hanks. José


Finally I resolved the error. That doesn't save because constrain was write wrong.

Error Code

 static constraint = {
     url(nullable:true)
 }

Good Code

static constraints = {
     url(nullable:true)
 }

Thanks all for yours answers. :P


But if i set the constraint nullable to true, the error show

again. I think that i should not set this cosntraint.

The nullable constraint works fine for me. If you don't specify it, you are surely get the error because that nullable=false in default.

Please try turn on the nullabe:true, and the restart Grails.

The model is linked to a mysql table with all properties except id allow null.

Actually, you don't need a pre-defined table, but if you do, I think it's best to NOT allow null at id field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜