Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 780
mkoryak Avatar asked Apr 14 '11 03:04

mkoryak


People also ask

What is db model in Gorm?

db. Model is the ordinary way of doing things. It allows you to tell gorm which model struct this operation relates to. It isn't always needed, as for example a simple Find with the right struct type will infer the model automatically.

How do you check the datatype of a table in SQL?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.

How does Gorm know which table?

It uses the name of your type. Here the type is User so gorm will use the users table by default. You can also configure it to not use the plural form if you'd like.

What is * Gorm db?

GORM provides First , Take , Last methods to retrieve a single object from the database, it adds LIMIT 1 condition when querying the database, and it will return the error ErrRecordNotFound if no record is found. // Get the first record ordered by primary key. db.First(&user)


2 Answers

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)

like image 144
Carlos Daniel Gadea Omelchenko Avatar answered Sep 22 '22 16:09

Carlos Daniel Gadea Omelchenko


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

like image 25
Victor Sergienko Avatar answered Sep 23 '22 16:09

Victor Sergienko