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.  [ 2 posts ] 
Author Message
 Post subject: Valid use of lazy property?
PostPosted: Mon Jul 25, 2005 1:34 pm 

Joined: Tue Oct 28, 2003 3:22 pm
Posts: 5
Location: Bethesda, MD
I've just hit a use case with my application that (to me) looks like I need to upgrade from Hibernate 2 to 3 to get lazy property support, but wanted to see if there was a better way.

Page table - contains a lot of metadata about a page (name, last_updated, author, content_type, etc...) and the binary data. This is the core table in my content management system.

PageInfo class - Everything in the Page table except the binary data property.

Page class - Child of PageInfo that includes the large binary data property.

PageMap class - many-to-many table between PageInfo classes, i.e., PageMap.parent is PageInfo and PageMap.child is PageInfo. This has a few other fields like ranking and mapping type.

Whenever I use the many-to-many PageMap table, I do not need the binary data property, so this has worked well. When I load a page that has a lot of relationships and I need to load the relationships, I don't want to load all the binary data into memory.

This has worked great, until now. I have an editor function for one content-type that requires me to load all the binary data for the children of page mapping relationship. The background is that most of the page maps are a list of links, e.g., links to a bunch of PDFs. Understandably I don't want to load the binary page data, nor would I edit that binary data or need to look at it. This allows PageMap to reference PageInfo.

However, this new content-type is a staff directory. When I edit the staff directory (which links to a bunch of pages, each of which is a staff member), I need to get the binary data property of each staff member to do sorts and display the names of the staff members during the editing process. This means I would need to change PageMap to reference Page. I don't even see a way to hack this editing session because I need to add and remove PageMap values. So, I have to keep PageMaps loaded and cannot separately also load the Page instances of all those PageInfo instances loaded from the PageMap instances.

It seems like lazy property loading would give me what I need... 95% of the time I do not want to load the binary data, but in this one use-case, assuming I set property lazy=true and do instrumentation, I can handle this. Also, I assume lazy loading would allow me to edit that lazy property if I needed to.

Assuming I do upgrade to Hibernate 3, I would remove the PageInfo class, move all mapping relationships from PageInfo to Page.

Is this a valid use of lazy property loading, or is there a better way to do this?

Serge Knystautas
e. serge@hibernate.org
p. 301-656-5501

 Post subject: Easy workaround
PostPosted: Mon Jul 25, 2005 11:06 pm 

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The easiest solution, avoiding bytecode instrumentation, is to use "fake" one-to-one mappings instead of properties. Remove the LOB fields from your existig class, create new classes referring to the same table, same primary key, and only the necessary LOB fields as properties. Specify the mappings as one-to-one, fetch="select", lazy="true". So long as your parent object is still in your session, you should get exactly what you want.

Bytecode instrumentation would also work, and with less development time.

Hope I've understood your question correctly. Good luck.

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.