2

我正在尝试将 Groovy 闭包(据称是可序列化的)作为我的 Grails 域对象之一的属性。目前我基本上是这样做的:

class MyClass {
    ....
    Closure myClosure
    static mapping = { myClosure size: 1024 * 1024, type: 'blob' }
}
new MyClass(myClosure: { ... do some stuff .. }.dehydrate()).save()

我尝试将“blob”更改为“二进制”,但这不起作用。我收到类似于以下内容的错误: context.GrailsContextLoader Error execution bootstraps: BootStrap$_obj_closure3 cannot be cast to java.sql.Blob

我应该如何设置我的域对象以便能够存储闭包?

我正在使用带有 Groovy 2.0 的 Grails 2.1.1

4

1 回答 1

3

我需要这个:

static mapping = {
    myClosure sqlType: 'blob'
}
于 2012-11-15T01:14:55.553 回答