【问题标题】:lazy column loading in Grails domain classGrails 域类中的延迟列加载
【发布时间】:2011-03-30 21:43:53
【问题描述】:

我有一个这样的域类:

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

 static mapping = {
  content lazy:true;
 }
}

我想启用对“内容”列的延迟加载,因为应用程序在不需要访问此列的情况下执行一些操作。

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

【问题讨论】:

    标签: hibernate grails grails-orm


    【解决方案1】:

    here 有一些关于使用 Hibernate 注释延迟加载特定列的讨论。

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

    class Document {
        String mime
        String name
        DocumentContent content
    }
    
    class DocumentContent {
        static belongsTo = [document:Document]
        byte[] data
    }
    

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

    【讨论】:

      【解决方案2】:

      您所说的应用程序做了一些事情是什么意思?你想建立什么?

      仅供参考。急切和延迟加载通常与关系有关,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
      

      在您的代码中没有关系。 content 是 Document 的一个属性,因此这里不适用延迟加载。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-07
        • 2011-09-07
        • 1970-01-01
        • 2011-11-05
        • 2013-07-03
        • 2015-06-21
        • 2018-11-22
        • 2011-09-20
        相关资源
        最近更新 更多