-->
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: Yet another Lazy Loading question
PostPosted: Fri Dec 14, 2007 3:47 pm 
Newbie

Joined: Fri Dec 14, 2007 3:08 pm
Posts: 3
I've read a lot of articles about lazy loading, but none seem to mention my specific question. Let's say my class looks like this:

Code:
public class Node {
private List<Node> children;
private Node parent;
private String name;
public List<Node> getChildren() {
  return children;
}
public Node getParent() {
  return parent;
}
public void setChildren(List<Node> children) {
  this.children = children;
}
public void setParent(Node parent) {
  this.parent = parent;
}
// ...
}


Now, if lazy loading is occurring and I call getChildren(), do ALL children below this node get loaded or only this nodes direct descendants? How do I only get the direct descendants?

Also, I keep seeing this:
If the association is nullable, Hibernate cannot lazy-load it by design.

And I've even read the explanation for why, but I still don't understand. Why can't my table be defined like this:
col1: myId
col2: myOneToOneId
...

In this case, hibernate does not have to query the one-to-one table to figure out if the one-to-one relationship exists. It can see if it exists by checking if it's OWN myOneToOneId is null. Why doesn't hibernate allow you to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 2:04 am 
Newbie

Joined: Thu Dec 13, 2007 8:18 pm
Posts: 7
I believe that Hibernate will only load the direct decedents when you call getChildren(). So it will load all the Children objects in the list but if those objects have any Objects that will be lazy loaded it will not fetch that data until it is requested.

It would be good if someone could check me on this though. I am still new to Hibernate myself and I could be wrong. But I think it makes sense they way I described it otherwise Hibernate could recurse down a deep tree and eat tons of memory for no reason.

The only reason I can think of that Hibernate won't lazy load a nullable association is so it can make a distinction between a NULL value and a NULL object reference. Again, I'm no hibernate expert yet, I just play one on TV, so this is all pure speculation.

I too would love to hear if someone else has some thoughts regarding this.

Hth,
Dave


Top
 Profile  
 
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.