0

I have a domain class:

class ProgramArea {
       String        programCd
       String        programArea
       String        description

    static constraints = {
programCd(nullable: false, unique: true)
              programArea(nullable: false, blank: false, unique: true)
              description(nullable: true, blank: true, maxSize: 50)
    }

}

In the database, I want the programCd field to be a ‘NOT NULL’ field. However, this is not user entered field. I have code in the controller to generate programCd. However, when I try to insert new data, I get a validation error saying programCd cannot be null.

If I modify the constraint for programCd as ‘nullable: true’, everything works fine. Can someone please let me know if there is a workaround for this?

2 Answers2

0

Please make sure that you are assigning the value of "programCd" to the object of the class. What seems to be an error here is that you might be generating the value of programCD but might have not added to the objec of the class, thus this value remains null.

Try checking your controller or paste the code here, so that we can help

Ekansh Rastogi
  • 2,418
  • 2
  • 14
  • 23
0

You may have to revalidate your domain instance after modifying it:

programAreaInstance.programCd = 'something'
programAreaInstance.validate()
user190117
  • 118
  • 5