Grails
  1. Grails
  2. GRAILS-2901

Default column size for String properties does not get validated

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.0.2
    • Fix Version/s: None
    • Component/s: Persistence
    • Labels:
      None
    • Testcase included:
      yes

      Description

      Given a simple domain class like this:

      class Book {
      	String title
      }
      

      Grails will create a database table called "Book" and a column called "title" with a default length of VARCHAR 255. If you set a value into the "title" attribute of Book that is longer than 255 characters, validation will not prevent hibernate from trying to save the object - so you end up with a JDBC exception that the value for the database column exceeds the size of the column.

      Is it possible to have validation validate the default size (i.e. 255) without having to explicitly define a maxSize constraint for String properties?

      The workaround for this is to specify size or maxSize constraints for ALL string properties on domain objects.

      Sample application with test case attached.

        Activity

        Hide
        Bobby Warner added a comment -
        Show
        Bobby Warner added a comment - This is a duplicate of: http://jira.grails.org/browse/GRAILS-7323

          People

          • Assignee:
            Bobby Warner
            Reporter:
            Mike Hugo
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development