-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Lazily loading a property
PostPosted: Mon Dec 01, 2003 9:43 am 
Newbie

Joined: Mon Oct 27, 2003 10:03 am
Posts: 15
I have a treelike data structure whose leaves are documentversions mapped to a table 'tbl_documentversion' that contains a given versions metadata like 'name', 'type', 'date_of_creation' etc. and the content proper. In order to let the user easily navigate this tree and quickly find the documentversion he/she is interested in I would like to prefetch all data except for the content which is typically 20 - 50 Megs for a single documentversion. I think the performance implications are obvious.

So what I would like to do is tell Hibernate to postpone fetching the content of any given documentversion until my code calls documentVersion.getContent(). This is what I have thought of so far:

1. Using Hibernate's 'lazy' attribute somehow. Unfortunately, the <property> element does not support this.

2. Transfering the content to a separate table 'tbl_content' linked to 'tbl_documentversion' via a one-to-one association. Unfortunately, <one-to-one> does not support the 'lazy' attribute either.

3. Writing a custom proxy class for DocumentVersion. I have no experience in this area and remain in doubt if doing so would allow me to achieve what I am trying to do. Any hints?

4. Writing a lightweight DocumentVersion, say DocumentVersionLight, that does not have the 'content' property, and making DocumentVersion extend DocumentVersionLight. It seems however that Hibernate does not support this since instances of both classes would be mapped to the same row in the same table. Moreover, there wouldn't be any discriminator-column since essentially the lightweight class would rather be an excerpt of the full class than its ancestor.

Currently I am investigating into the possibilities the latest Hibernate 2.1 betas might offer, especially into native SQL queries. But what makes the current solution so attractive is that right now I can get away with something like

Tree data = (Tree) session.load(Tree.class, id);

and Hibernate will walk the tree for me and fetch all nodes. Now if only I could tell Hibernate to stop when it reaches the 'content' property of the 'documentversion' node.

Any help would be greatly appreciated. Thanks,

Olaf


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 9:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(a) one-to-one may certainly be lazy (use the proxy attribute)
(b) If supported by your driver You should use a JDBC Blob or Clob to represent the 50 meg of data - these are streamed lazily at the driver level
(c) check out the "lightweight class" pattern on the wiki


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 10:40 am 
Newbie

Joined: Mon Oct 27, 2003 10:03 am
Posts: 15
Thanks for your quick reply.

gavin wrote:
(a) one-to-one may certainly be lazy (use the proxy attribute)

According to the docs the <one-to-one> element does neither support the lazy nor the proxy attribute. Furthermore, the docs seem to imply that specifying a proxy class in the <class> element of a mapping does not in itself enable lazy loading. As I understand it doing so merely tells Hibernate to use the given proxy IF the lazy attribute in, say, a <set> element at the other end of the association is set to 'true'. So do you say that if the target class (Content, in my case) of a one-to-one association specifies a proxy in its mapping Hibernate will automatically use lazy loading?

(b) If supported by your driver You should use a JDBC Blob or Clob to represent the 50 meg of data - these are streamed lazily at the driver level

This is probably not what I need, but I will look into it.

(c) check out the "lightweight class" pattern on the wiki


Thanks for the tip. I will surely do so.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.