在Grails域类中加载惰性列

在Grails域类中加载惰性列

本文介绍了在Grails域类中加载惰性列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个域类:

  class Document {
String mime;
字符串名称;
byte [] content;

static mapping = {
content lazy:true;


$ / code $ / pre

我想启用延迟加载到内容列,因为应用程序执行某些内容而不需要访问此列。



但是lazy:true选项不起作用......任何想法或解决方法?

解决方案

应用程序的意思是什么?你试图建立什么?



FYI。急切和懒惰的加载通常与关系有关,默认情况下grails启用了延迟加载。例如

 课本{b $ b static belongsTo = Author 
字符串名称
作者author


类作者{
static hasMany = [books:Book]
字符串名称
}

def author = Author .get(author_id)
def authorBooks = author.books // ===>集合与默认的延迟关联

在你的代码中没有关系,content是Document的一个属性,因此懒加载不适用于此。




I have a domain class like this:

class Document {
 String mime;
 String name;
 byte[] content;

 static mapping = {
  content lazy:true;
 }
}

and I'd like to enable lazy loading to the "content" column, because the application does some stuff without the need of access to this column.

But the lazy:true option didn't work... any idea or workaround?

解决方案

What do you mean by the application does some stuff? and what are you trying to establish?

FYI. eager and lazy loading usually has to do with relations, grails by default has lazy loading enabled. e.g."

Class Book{
   static belongsTo = Author
   String Name
   Author author
}

Class Author{
   static hasMany = [books:Book]
   String Name
}

def author = Author.get(author_id)
def authorBooks = author.books //===> collection with lazy association by default

In your code there is no relation. content is a property of Document, hence lazy loading doesn't apply here.

http://grails.org/doc/1.0.x/guide/5.%20Object%20Relational%20Mapping%20(GORM).html

这篇关于在Grails域类中加载惰性列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 07:40