如何让Grails将我的String字段映射到Clob? [英] How do I get Grails to map my String field to a Clob?

查看:115
本文介绍了如何让Grails将我的String字段映射到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)
    }
} 

我的印象是Grails会想出来使用CLOB而不是VARCHAR,基于我传递的足够大的值maxSize约束,而不是在控制台中收到此错误消息:

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)

我需要一个显式的sqlType映射?我尝试使用不同的maxSize值,并将其完全丢弃,没有任何区别。另外添加 sqlType:clob sqlType:text 不起作用。

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.

我在使用IBM DB2-Express的Grails 1.3.7上。

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

推荐答案

找到答案。 阅读文档找不到任何东西。

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

工作的变化是将clob列的映射更改为

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

foo column: 'STUFF', type: "text"

这篇关于如何让Grails将我的String字段映射到Clob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆