6

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.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276

4 Answers4

11

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"
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
4

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.

luisZavaleta
  • 1,160
  • 11
  • 21
0

Although actual Oracle DB column type is CLOB, type:'text' didn't help when dbCreate is set to validate in DataSource.groovy.

But this works for my Grails 2.2.0:

static mapping = { stuff sqlType: 'clob' }
Pavel Vlasov
  • 4,206
  • 6
  • 41
  • 54
0

I used " Clob data" in my Grails project and that worked fine.

Can you use Clob ?

class Foo
{
 Clob stuff
 }
Ben W
  • 2,469
  • 1
  • 24
  • 24
  • That would be one way to do it, I guess. I'd really like to see an answer that allows me to use a string in the domain object. There must be a UserType for this. – Nathan Hughes Feb 14 '12 at 02:03