我正在尝试使Grails域类的一个字段延迟加载。实际上,这是数据库中的CLOB列,但已映射到Grails域类中的String字段。
因此,我为此类创建了以下休眠映射:
<hibernate-mapping>
<class name="MyClass" table="my_table">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="clobCol" type="materialized_clob" lazy="true"/>
<property name="someOtherField" type="string"/>
</class>
</hibernate-mapping>
我的域类如下所示:
class MyClass {
String someOtherField
String clobCol
static constraints = {
clobCol(nullable: true)
}
}
我期望使用DetachedCriteria查询数据库时
clobCol
应该是懒惰的。但是实际上,它正在被热切地加载。是否可以通过这种方式使字段变得懒惰?如果是,那么我在做什么错?如果不是这样,那么在没有大量重构类和现有查询的情况下,使
clobCol
变得懒惰的最佳方法是什么?
最佳答案
我相信您可以通过在域类中声明一个名为fetchMode的属性来实现此目的,该属性包含属性/访存类型的映射
class MyClass {
static fetchMode = [clobCol: 'lazy']
...
}
关于hibernate - Grails/GORM延迟加载CLOB字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26849350/