1

I followed the instructions that I found many places online for how, for a Grails 2.2.4 domain object property, to create a default value on its corresponding MySQL 5.5 column.

Unfortunately, the columns that are supposed to have a default value do not have a default value applied to their MySQL columns.

Below are the relevant extracts from my domain object code. Is anything wrong?:

class SelectOption {

    int minSelectCount = 0
    int maxSelectCount = 1

    static constraints = {
        minSelectCount nullable: false, min: 0, defaultValue: "0"
        maxSelectCount nullable: false, min: 1, defaultValue: "1"
    }
}
4

1 回答 1

5

Try putting defaultValue in the mapping block instead of constraints block.

static mapping = {
    minSelectCount defaultValue: "0"
    maxSelectCount defaultValue: "1"
}
于 2015-03-23T02:14:59.633 回答