问题
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.
回答1:
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"
回答2:
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.
回答3:
I used " Clob data" in my Grails project and that worked fine.
Can you use Clob ?
class Foo
{
Clob stuff
}
回答4:
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' }
来源:https://stackoverflow.com/questions/9268777/how-do-i-get-grails-to-map-my-string-field-to-a-clob