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?