Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Grails to map my String field to a Clob?

My domain class looks like this:

package com.initech.tps

class Foo
{
    String stuff

    static mapping = {
        // mapping to a legacy table as opposed to letting Grails create it
        table name: 'FOO', schema: 'TPS'
        id generator: 'sequence', params: [sequence: 'MY_SEQ'], 
            column: 'FOO_ID', sqlType: 'integer' 
        foo column: 'STUFF'
    }

    static constraints = {
        stuff(nullable: true, maxSize: 40000)
    }
} 

I was under the impression Grails would figure out to use a CLOB instead of a VARCHAR based on my passing in a big enough value for the maxSize constraint, instead I get this error message in the console:

org.hibernate.HibernateException: Wrong column type in FOO for column STUFF. 
Found: clob, expected: varchar(40000)

Do I need an explicit sqlType on the mapping? I tried using different values of maxSize, and leaving it out altogether, with no difference. Also adding sqlType: clob or sqlType: text doesn't work.

I'm on Grails 1.3.7, using IBM DB2-Express.

like image 249
Nathan Hughes Avatar asked Feb 13 '12 22:02

Nathan Hughes


2 Answers

Found the answer. Nothing like reading the documentation to find something out.

The change that worked was changing the mapping for the clob column to

foo column: 'STUFF', type: "text"
like image 160
Nathan Hughes Avatar answered Sep 28 '22 08:09

Nathan Hughes


I know it's too late, but for future references:

you just has to add a mapping

    static mapping = {  stuff type:'text' }

And that's all, grails change the data type to clob or any other that can hold large strings based in the database you're using.

like image 29
luisZavaleta Avatar answered Sep 28 '22 09:09

luisZavaleta