-->
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: Recursive entity relationships & out of memory errors
PostPosted: Sat Apr 19, 2008 4:47 pm 
Newbie

Joined: Tue May 08, 2007 10:55 am
Posts: 5
The following problem concerns a web crawler.

Let's say you have the entity class "Page" to represent a Page downloaded from the internet:

Code:
@Entity
class Page
{
int id;
String pageUrl;
String pageText; //contains the whole page contents

@OneToMany(cascade = CascadeType.ALL)
List<Page> children;
}


As you can see, a web page can link to other web pages, which are stored as the "children". Now the problem is, children can also have children ad infinitum . Currently what I do is:

Page rootPage = new Page("http://www.msn.com");
entityManager.persist(rootPage);
rootPage = crawl(rootPage);


During the crawl memory usage goes up rapidly, until and "out of memory" exception is thrown.

Any recommendations on how to limit memory usage?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 20, 2008 11:49 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 4:57 am
Posts: 22
Location: Bangalore,India
try to make use of hibernate.jdbc.batch_size property

OR

make use of session.flush() and session.clear() at regular intervals.

_________________
Naresh Waswani
+91-9986461501


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 3:08 am 
Newbie

Joined: Tue May 08, 2007 10:55 am
Posts: 5
Thanks, but the real problem is that the rootPage is growing without bounds.

The idea behind my code is that I call the entitymanager once with entityManager.persist(rootPage), and then the function crawl(rootPage) executes the statement rootPage.setChildren(List<Page> childPages) and for each child also executes child.setChildren, and so on infinitely & recursively.

Each time setChildren is called, Hibernate adds the children to the database table Page and links them to the parent in the same table...


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.