-->
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.  [ 8 posts ] 
Author Message
 Post subject: "Out of Memory Error" from Hibernate-Tapestry-Tomc
PostPosted: Thu Apr 22, 2004 6:55 am 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
My team are using Hibernate - Tapestry and Tomcat as our web project architecture.

Version:
Tapestry 3.0 beta
Hibernate 2.1.1
Tomcat 4.1.29

However the performance is very slow, and we're getting "Out of Memory Error" after few times accessing the database. Can anyone help me solving this problem?

If this isn't really a logic error, is there going to be the patch or trick posted for this kind of problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 9:38 am 
Senior
Senior

Joined: Wed Mar 24, 2004 11:40 am
Posts: 146
Location: Indianapolis, IN, USA
I doubt that it is a problem with Hibernate because otherwise everyone would be complaining about this. I use Hibernate, Struts, Resin and SAPDB and have had no such problems. Check to ensure that you are closing your hibernate sessions. If you turn your Log4J logger for Hibernate to DEBUG level, it will log whenever your session is closed.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 10:28 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
ok lemme give the code that generate some warnings :

public City byName(String name) throws HibernateException
{
System.out.println("Retrieving the City");
sess = sessFact.openSession();
try
{

List aList = sess.find("from City as city where lower(city.name)=lower(:name)", name,Hibernate.STRING);

if (aList.size() == 0)
{
System.out.println("No City named " + name);
return null;
}
else
{
theCity = (City) aList.get(0);
System.out.println(theCity);
System.out.println(" City is successfully retrieved");
}

}
catch(HibernateException he)
{
throw he;
}
finally
{
sess.close();
}
return theCity;
}


And this is the log :
Initializing successful
Retrieving the City
09:21:53,625 DEBUG SessionImpl:531 - opened session
09:21:53,625 DEBUG SessionImpl:1497 - find: from com.andrewtani.tm.hbm.ref.City as city where lower(city.name)=lower(:name)
09:21:53,625 DEBUG QueryParameters:105 - parameters: []
09:21:53,640 DEBUG QueryTranslator:147 - compiling query
09:21:53,671 DEBUG SessionImpl:2210 - flushing session
09:21:53,671 DEBUG SessionImpl:2403 - Flushing entities and processing referenced collections
09:21:53,671 DEBUG SessionImpl:2746 - Processing unreferenced collections
09:21:53,671 DEBUG SessionImpl:2760 - Scheduling collection removes/(re)creates/updates
09:21:53,671 DEBUG SessionImpl:2234 - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
09:21:53,687 DEBUG SessionImpl:2239 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
09:21:53,687 DEBUG SessionImpl:1782 - Dont need to execute flush
09:21:53,687 DEBUG QueryTranslator:199 - HQL: from com.andrewtani.tm.hbm.ref.City as city where lower(city.name)=lower(:name)
09:21:53,687 DEBUG QueryTranslator:200 - SQL: select city0_.ID as ID, city0_.CITY_NAME as CITY_NAME, city0_.CITY_DESCRIPTION as CITY_DES3_ from CITIES city0_ where (lower(city0_.CITY_NAME)=lower(?))
09:21:53,687 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
09:21:53,687 DEBUG SQL:237 - select city0_.ID as ID, city0_.CITY_NAME as CITY_NAME, city0_.CITY_DESCRIPTION as CITY_DES3_ from CITIES city0_ where (lower(city0_.CITY_NAME)=lower(?))
Hibernate: select city0_.ID as ID, city0_.CITY_NAME as CITY_NAME, city0_.CITY_DESCRIPTION as CITY_DES3_ from CITIES city0_ where (lower(city0_.CITY_NAME)=lower(?))
09:21:53,687 DEBUG BatcherImpl:241 - preparing statement
09:21:53,906 DEBUG Loader:197 - processing result set
09:21:53,906 DEBUG Loader:226 - done processing result set (0 rows)
09:21:53,906 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
09:21:53,921 DEBUG BatcherImpl:261 - closing statement
09:21:53,921 DEBUG Loader:239 - total objects hydrated: 0
09:21:53,921 DEBUG SessionImpl:3082 - initializing non-lazy collections
No City named
09:21:53,921 DEBUG SessionImpl:549 - closing session
09:21:53,921 DEBUG SessionImpl:3294 - disconnecting session
09:21:53,937 DEBUG JDBCExceptionReporter:18 - SQL Warning
java.sql.SQLWarning: [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to ATC
at com.microsoft.jdbc.base.BaseWarnings.createSQLWarning(Unknown Source)
at com.microsoft.jdbc.base.BaseWarnings.get(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getWarnings(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$ProxyConnectionInvocationHandler.invoke(C3P0PooledConnection.java:645)
at com.mchange.v2.c3p0.impl.$Proxy0.getWarnings(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.closeConnection(BatcherImpl.java:289)
at net.sf.hibernate.impl.SessionImpl.disconnect(SessionImpl.java:3310)
at net.sf.hibernate.impl.SessionImpl.close(SessionImpl.java:552)
at com.andrewtani.tm.hbm.query.GetCity.byName(GetCity.java:116)
at com.andrewtani.tm.hbm.query.GetCity.<init>(GetCity.java:36)
at com.andrewtani.tm.hbm.query.GetCity.main(GetCity.java:123)
09:21:53,953 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
09:21:53,953 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to ATC
09:21:53,953 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
09:21:53,953 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to 'ATC'.
09:21:53,953 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
09:21:53,953 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
09:21:53,953 WARN JDBCExceptionReporter:20 - SQL Warning: 0, SQLState:
09:21:53,953 WARN JDBCExceptionReporter:28 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to us_english.
09:21:53,968 DEBUG SessionImpl:561 - transaction completion


Did I close the session correctly? is this warning has something to do with that Out of Memory error? OR is it Tapestry/Tomcat problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 7:40 am 
Regular
Regular

Joined: Wed Dec 31, 2003 4:26 am
Posts: 108
Location: Berkeley, CA
Are you setting lazy="false" on your relationships? Doing so can cause large numbers of objects to be created for seemingly simple queries.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 23, 2004 8:28 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I do not think this code can produce out of memory error, probably your
"" setting is too low. Try something like -Xmx128M or more.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 25, 2004 11:09 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
eepstein wrote:
Are you setting lazy="false" on your relationships? Doing so can cause large numbers of objects to be created for seemingly simple queries.


but in that particular code above, I don't have any lazy at all, but the out of memory error still shows up on that particular case....

Oh man, this is frustrating.
The spec of the computer : (just in case it would help)

Pentium4-2,4 GB, RAM 256 MB...


Top
 Profile  
 
 Post subject: Bad DEsign???
PostPosted: Sun Apr 25, 2004 11:49 pm 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
baliukas wrote:
I do not think this code can produce out of memory error, probably your
"" setting is too low. Try something like -Xmx128M or more.



Well, it has been done too... I'm expecting something like bad object design, like "Creating too many objects at once...."

Like this : I have all queries on a class

(e.g GetCity.java( method= byName(),listAllCities() ),
GetState.java ( method= byName(),listAllStates() ),
GetCountry.java ( method= byName(),listAllCountries() )

Is this truly a bad design?? I create this so that these (I assume those are called POJO) could ENCAPSULATE the action of opening session, loading object from database, and closing up the session

BUT in this case, EACH time I create a new object, I have to create another SessionFactory right? Is this a bad design???
Coz at the Hibernate Documentation it is said that SessionFactory is heavy to maintain...

So is there any way around that problem? Should I have ALL the queries in one single JAVA class for example, so I don't have to configure and build a session factory for each Query??

Thanks guys


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 12:53 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Create session factory once and put it to application context. It is a good idea
to create session once per request, not per method. It works well for web applications and does not leak any resources.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.