Search code examples
grails

String size in Grails too big for database field


I have Message domain class that is used to send an email to site administrators

class Message {

  String name
  String subject
  String body

}

I thought String would not have a maximum size but when people put in messages that are too big then I see exceptions in my log files. For now I put a constraint in to limit the size of the message to 250 but cannot make it bigger or else the save fails. I am using PostgreSQL 9.1.1 and Grails 1.3.7. Does anyone know a way to fix this?


Solution

  • You can specify the data type using a constraint:

    static constraints = {
      body type:'text'
    }