Grails 域类中的惰性列加载

发布于 2024-10-29 04:17:50 字数 242 浏览 6 评论 0原文

我有一个像这样的域类:

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

 static mapping = {
  content lazy:true;
 }
}

并且我想启用对“内容”列的延迟加载,因为应用程序无需访问此列即可执行一些操作。

但是lazy:true选项不起作用...有什么想法或解决方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏剧牡丹亭 2024-11-05 04:17:50

此处有一些关于使用 Hibernate 注释延迟加载特定内容的讨论柱子。

另一种可能性是将 Document 对象分成两部分。像这样:

class Document {
    String mime
    String name
    DocumentContent content
}

class DocumentContent {
    static belongsTo = [document:Document]
    byte[] data
}

由于这是一个关系,GORM 默认情况下会延迟加载 DocumentContent。

There is some discussion here about using Hibernate annotations to lazily load a specific column.

Another possibility is to break your Document object into two pieces. Something like this:

class Document {
    String mime
    String name
    DocumentContent content
}

class DocumentContent {
    static belongsTo = [document:Document]
    byte[] data
}

Since this is a relation, GORM will lazily load the DocumentContent by default.

淡写薰衣草的香 2024-11-05 04:17:50

应用程序执行某些操作是什么意思?你想建立什么?

供参考。急切加载和延迟加载通常与关系有关,grails 默认情况下启用延迟加载。例如“

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

在您的代码中没有关系。内容是文档的属性,因此延迟加载在这里不适用。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文