-->
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: java.lang.OutOfMemoryError: Java heap space
PostPosted: Thu Jul 19, 2007 4:52 am 
Newbie

Joined: Thu Jul 19, 2007 4:15 am
Posts: 2
Hibernate version: 3.1

Mapping documents:
Snippet of mapping:
<many-to-one name="location" class="data.bean.Location" fetch="select">
<column name="LOCATION2PARENTLOCATION" precision="22" scale="0" />
</many-to-one>

Code between sessionFactory.openSession() and session.close():
Yes...


Full stack trace of any exception that occurs:
java.lang.OutOfMemoryError: Java heap space

Name and version of the database you are using:
Oracle 10g

The problem arises when retrieving a location for a network node. This location has a parentLocation which then has a parentLocation etc reference in the Location table.

I need to retrieve the all parent locations upward i.e. a complete list of parents grandparents etc.

Which is then used to determine the folders that these locations belong to and such the folders the network node belongs to.

I have enabled these hibernate properties which seems to have speeded up the querying:

<property name="jdbc.batch_size">50</property>
<property name="hibernate.max_fetch_depth">7</property>

The session is obtained through a HibernateBaseDAO:
public class BaseHibernateDAO implements IBaseHibernateDAO {

public Session getSession() {
return HibernateSessionFactory.getSession();
}

public static void flushSession(){
HibernateSessionFactory.getSession().flush();
HibernateSessionFactory.getSession().clear();
}

public static void closeSession(){
HibernateSessionFactory.getSession().close();
}

}

The LocationDAO retrieves a Location data bean:
public Location findById( java.lang.Long id) {
log.debug("getting Location instance with id: " + id);
try {
Location instance = (Location) getSession()
.get("data.bean.Location", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}

The classes using the DAO methods flush and close the session after:

public List<NetworkNode> getNodeLocations(List<NetworkNode> nodesList){
Iterator nodesIter = nodesList.iterator();
while(nodesIter.hasNext()){
NetworkNode temp = (NetworkNode)nodesIter.next();
LocationDAO locationDAO = new LocationDAO();
Location location = locationDAO.findById(new Long(temp.getLocationID()).longValue());
temp.setParentLocationList(this.getParentLocationList(location));
temp.setLocationName(location.getName());
}
BaseHibernateDAO.flushSession();
BaseHibernateDAO.closeSession();
return nodesList;
}

I have bumped up the JVM memory:
-Xms1024m -Xmx1280m -XX:PermSize=64M -XX:MaxPermSize=256M

There are approx 1202 nodes which have a location and then 6 levels of parent locations.

I read in all the nodes but then process for parent locations 10 nodes at a time. Still I seem to run 0ut of memory. If I dont scan for all locations for each node then the app is fine.

I cant seem to think that so much memory is required?
Any help would be much appreciated...

Regards,
AT
atheba@gmail.com


Top
 Profile  
 
 Post subject: RE:
PostPosted: Fri Jul 20, 2007 5:51 am 
Newbie

Joined: Thu Jul 19, 2007 4:15 am
Posts: 2
Okay... Here is the deal:

I took out the hibernate many-to-one mapping and had it just pull the parent location reference as a Long.

Next I wrote simple select statement using JDBC:

select locationid, name, location2parentlocation from location START WITH locationid = ? CONNECT BY PRIOR location2parentlocation = locationid

I found that there were a handful of queries returning:

ORA-01436:
CONNECT BY loop in user data

Cause:
The condition specified in a CONNECT BY clause caused a loop in the query, where the next record to be selected is a descendent of itself. When this happens, there can be no end to the query.

Turns out Hibernate found the parent location and then got stuck in a loop using up memory until the java heap space error.

It aint really hibernate fault but it would be nice if Hobernate could check for this type of situation.

Regards,
AT


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 11, 2007 8:42 pm 
Beginner
Beginner

Joined: Thu Jan 11, 2007 7:19 pm
Posts: 20
Location: Argentina, Buenos Aires
I don't know if it is too late,

But begin with adding -XX:MaxPermSize=256m to your jvm parameters,
and see what happens.

Hope it helps


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.