本文介绍了如何让 Grails 将我的 String 字段映射到 Clob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的域类如下所示:

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 会根据我为 maxSize 约束传递的足够大的值来计算使用 CLOB 而不是 VARCHAR,但我在控制台中收到以下错误消息:

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: clobsqlType: 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.

我在 Grails 1.3.7 上,使用 IBM DB2-Express.

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 10:00