-->
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: lazy loading within a (large) associated collection
PostPosted: Wed Dec 07, 2005 1:37 pm 
Newbie

Joined: Wed Dec 07, 2005 1:27 pm
Posts: 8
I apologize if this is covered somewhere in documentation; I haven't been able to find it.

I have a uni-directional one-to-many relationship defined by a <map>. (The parent knows about the children, but not vice-versa). The problem is that the parent can have so many children that it is not reasonable to load the entire collection of children at once - the application will exceed memory restrictions.

Is it possible to make the contents of this collection load lazily? I'm thinking ideally by batch. My map-key is (essentially) a date (actually it's a custom type that represents a date). What I'd like is that when I do this:

parent.getChild(date);

that Hibernate would load a batch of that parent's children for keys on or around that date.

Is this possible, or do I need to essentially populate the map manually?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 2:02 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Maybe you want to evaluate filters:
http://www.hibernate.org/hib_docs/v3/re ... lters.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 5:00 pm 
Newbie

Joined: Wed Dec 07, 2005 1:27 pm
Posts: 8
Mike,

Thanks, your answer is helpful, and I think it may solve my problem.

It seems, though, that there ought to be a more seamless way to do what I'm trying to do. Using filters allows me to do something like this:

Parent parent = session.load(...);
session.enableFilter("byDate").setParameter("date", date1);
Child child1 = parent.getChild(date1);
session.enableFilter("byDate").setParameter("date", date2);
Child child2 = parent.getChild(date2);

But ideally I'd like to do the above, without having to set the filter parameters each time I want to retrieve a new child from the parent. (Maybe in the persistence layer I don't know exactly what children I'll need, and when I'm calling parent.getChild(), I'm not in Hibernate-aware code, so it's not convenient to deal with filters.) What would be cool is if every time I call getChild(), Hibernate could anticipate whether it needs to go to the database to retrieve another batch of children.

Oh well, like I said, I think I can do what I need with filters. Thanks for your response.


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.