开发者

GORM: how to set datatype of a value in a Map

开发者 https://www.devze.com 2023-02-25 15:37 出处:网络
in my domain object i have a map: Map<String, String> stuff GORM automatically creates a table where the key and the value are varchar(255).

in my domain object i have a map:

Map<String, String> stuff

GORM automatically creates a table where the key and the value are varchar(255).

i need the value to be LongText instead. How do i do this thing? 开发者_开发技巧

Also, is there a workaround for this that doesnt involve using the hibernate config?


I think you can declare this setting in the mapping closure of your Domain class.

Constraint for a String field so that its MySQL column type is TEXT:

static mapping = {
   myTextField type: 'text'
}

Maybe this can help you out: Grails Guide (5.5.2.1 Table and Column Names)


I'm afraid only via Hibernate XML config and specifying a key mapping for the stuff.


If you want to have more control of how the database is generated/updated then it is better to use a database migration then letting Hibernate manage it. We use Liquibase which is very easy to use and flexible and there is already a Grails plug in for it. Also, if I am not mistaken database migrations are going to be integrated in Grails core for version 1.4 so you will be able to use schema migrations without having to install any plug in.

0

精彩评论

暂无评论...
验证码 换一张
取 消