Column type in grails not working

2019-09-08 15:20发布

This is my model.

class Review {
String review
Date date
int numberOfComments
String status
static belongsTo = [game:Game, user:User]
static hasMany=[comment:Comment]
static mapping ={
    numberOfComments    defaultValue: "0"
    review type: 'text'
}

static constraints = {

}

when I inputted 400 character text it generated this error

enter image description here

I don't know why the review type: 'text' is not working. can someone help?

标签: grails gorm
3条回答
叼着烟拽天下
2楼-- · 2019-09-08 15:58

In fact grails GORM sometimes have problems with updating column types, especially if they contain any data. Try to delete selected column/table in database and restart application.

Ensure also that you have changed in conf/DataSource.groovy

dbCreate = "update"

to

dbCreate = "create-drop"

Edited: Firstly I didn't notice that you are using h2 db. Please check out this answer for text type in h2 database.

查看更多
smile是对你的礼貌
3楼-- · 2019-09-08 15:59

Maybe you can use an sqlType instead like

class Email {

    String body

    static mapping = {
        body sqlType: "longtext"
    }
查看更多
姐就是有狂的资本
4楼-- · 2019-09-08 16:20

you can make it a blob type

static mapping = {
    review (type:’blob’)
}

Note type is default properties for Grails 2.0, if you use newer version of grails you should use sqlType.

Check it here: http://grails.github.io/grails-doc/latest/ref/Database%20Mapping/column.html

查看更多
登录 后发表回答