Miguel Prz
Miguel Prz

Reputation: 13792

lazy column loading in Grails domain class

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?

Upvotes: 2

Views: 4540

Answers (2)

SpookyGuru
SpookyGuru

Reputation: 51

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.

Upvotes: 5

z.eljayyo
z.eljayyo

Reputation: 1289

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

Upvotes: 4

Related Questions