0

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}
        }
    }
}

Thanks. José

jjczopek
  • 3,319
  • 2
  • 32
  • 72
richardhell
  • 969
  • 2
  • 10
  • 22
  • Jose, by default the nullable constraint is set to false, I see that you have the constraint commented in your question about, is that really the case? Do you have the nullable constraint for url set to true? Because if it is not set then it makes sense you are getting that error when saving. – Maricel Mar 17 '11 at 21:35
  • ok. I executed grails clean but the error continue. – richardhell Mar 18 '11 at 23:40
  • @Maricel I set nullable to true but the error continue – richardhell Mar 18 '11 at 23:41

2 Answers2

3

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

corvec
  • 288
  • 4
  • 14
richardhell
  • 969
  • 2
  • 10
  • 22
0
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.

Hoàng Long
  • 10,746
  • 20
  • 75
  • 124