-->
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.  [ 11 posts ] 
Author Message
 Post subject: OutOfMemory exception initializing AnnotationConfiguration
PostPosted: Sun Apr 05, 2009 12:30 am 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
Hi

I am new to hibernate, I wrote a simple application to store some objects into the backend mysql database. I used eclipse on windows to test this sample and it was working fine with that. Then in order to make the build/run simpler I wrote the ant file so that I can invoke it from command prompt as well. And then when I tried invoking the program from Ant, I started getting Out Of Memory exception. I have tried setting ANT_OPTS to increase the initial heapsize but it seems like it doesn't affect the output no matter how much inital memory I specify. I tried debugging it with writing print statements and looking at the stack trace, the problem seem to happen at the initialization of the AnnotationConfiguration object. I am not sure what is causing this to throw out of memory exception, I would appreciate if anybody can help me debug this more thorughly, I want to run it on other machine and for that I want to be able to run it with my ant build.


I am getting the following error in the code where I am trying to initialize
AnnotationConfiguration() object.


Here is the source code to manage hibernate session:

public class SessionFactoryUtil {
/** The single instance of hibernate SessionFactory */
private static org.hibernate.SessionFactory sessionFactory;
/**
* disable contructor to guaranty a single instance
*/
private SessionFactoryUtil() {
}

static{
// Annotation and XML
System.out.println("Getting the session Factory for the first time when the class is loadded!!!");
//sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
AnnotationConfiguration configs = new AnnotationConfiguration();
System.out.println("Got the session Factory for the first time when the class is loadded!!!");

sessionFactory = configs.configure().buildSessionFactory();
// XML only
// sessionFactory = new Configuration().configure().buildSessionFactory();
}

public static SessionFactory getInstance() {
System.out.println("Get session Factory instance!!!");
return sessionFactory;
}

/**
* Opens a session and will not bind it to a session context
* @return the session
*/
public Session openSession() {
System.out.println("Open Session!!!");
return sessionFactory.openSession();
}

/**
* Returns a session from the session context. If there is no session in the context it opens a session,
* stores it in the context and returns it.
* This factory is intended to be used with a hibernate.cfg.xml
* including the following property <property
* name="current_session_context_class">thread</property> This would return
* the current open session or if this does not exist, will create a new
* session
*
* @return the session
*/
public Session getCurrentSession() {
System.out.println("Get current Session!!!");
return sessionFactory.getCurrentSession();
}

/**
* closes the session factory
*/
public static void close(){
System.out.println("Close Session!!!");
if (sessionFactory != null)
sessionFactory.close();
sessionFactory = null;

}
}



] Get the session!!!!
] Getting the session Factory for the first time when the class is loadded!!!
] Exception in thread "main" java.lang.ExceptionInInitializerError
] at org.hibernate.cfg.AnnotationConfiguration.<clinit>(AnnotationConfiguration.java:78)
] at com.test.rss.hibernate.dao.SessionFactoryUtil.<clinit>(Unknown Source)
] at com.test.rss.hibernate.dao.CraigslistDAO.createPosting(Unknown Source)
] at com.test.rss.reader.CraigslistFeedReader.processFeed(Unknown Source)
] at com.test.rss.main.MainDriver.main(Unknown Source)
] Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: java.lang.OutOfMemoryError: Java h
(Caused by java.lang.OutOfMemoryError: Java heap space) (Caused by org.apache.commons.logging.LogConfigurationException: java.lang.OutOfMemoryError: Java h
(Caused by java.lang.OutOfMemoryError: Java heap space))
] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:630)
] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)
] at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:69)
] at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
] at org.hibernate.cfg.annotations.Version.<clinit>(Version.java:12)
] ... 5 more
] Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.OutOfMemoryError: Java heap space (Caused by java.lang.OutOfMemoryError: Java
)
] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:630)
] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)
] at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:69)
] at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:88)
] at org.apache.log4j.Category.<init>(Category.java:52)
] at org.apache.log4j.Logger.<init>(Logger.java:22)
] at org.apache.log4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:39)
] at org.apache.log4j.Category.getLogger(Category.java:59)
] at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)
] at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)
] at sun.reflect.GeneratedConstructorAccessor3.newInstance(Unknown Source)
] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
] at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:608)
] ... 10 more
] Caused by: java.lang.OutOfMemoryError: Java heap space
] Java Result: 1


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Hibernate 3.3.1
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="com.test.rss.reader.Posting" table="craigslist">
<id name="id" column="posting_id" />
<property name="price" column="price" />
<property name="title" column="title" />
<property name="link" column="link" />
<property name="description" column="description" />
</class>
</hibernate-mapping>

?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.rss.reader.Address" table="location">
<id name="address_id" column="address_id" >
</id>
<property name="zipcode" column="zipcode" />
<property name="city" column="city" />
</class>
</hibernate-mapping>



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

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 4:10 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Post your ant file.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 1:33 pm 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
I am using hibernate for persisting objects to mysql database as well as for indexing/search using hibernate search... Please let me know if you need any more information, I would highly appreciate your help.

Below is the ant file that I am using and following are the contents of the lib directory (this is the directory containing all the jars, that I used to construct the class path):

antlr-2.7.6.jar
commons-codec-1.3.jar
commons-collections-3.1.jar
commons-collections-3.2.1.jar
commons-httpclient-3.1.jar
commons-io-1.4.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
cssparser-0.9.5.jar
dom4j-1.6.1.jar
dom4j.jar
ejb3-persistence.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-core.jar
hibernate-search.jar
hibernate-testing.jar
hibernate3.jar
htmlunit-2.4.jar
htmlunit-core-js-2.4.jar
javassist-3.4.GA.jar
jcl104-over-slf4j-1.5.1.jar
jdom.jar
jms.jar
jsr250-api.jar
jta-1.1.jar
jta.jar
lib.txt
log4j-over-slf4j-1.5.1.jar
lucene-core.jar
lukeall-0.9.2.jar
mysql-connector-java-5.1.7-bin.jar
nekohtml-1.9.11.jar
README.txt
rome-1.0.jar
sac-1.3.jar
serializer-2.7.1.jar
slf4j-api-1.5.1.jar
slf4j-api-1.5.2.jar
slf4j-api.jar
slf4j-jcl-1.5.1.jar
slf4j-jdk14-1.5.1.jar
slf4j-log4j12-1.5.1.jar
slf4j-migrator-1.5.1.jar
slf4j-nop-1.5.1.jar
slf4j-simple-1.5.1.jar
solr-common.jar
solr-core.jar
xalan-2.7.1.jar
xercesImpl-2.8.1.jar
xml-apis-1.3.04.jar



Ant build.xml:

<project name="RSSReader" default="dist" basedir=".">
<description>simple example build file</description>
<!-- set global properties for this build -->
<property name="src" location="src" />
<property name="librarydir" value="lib"/>
<property name="build" location="build" />
<property name="dist" location="dist" />




<target name="init">
<!-- Create the time stamp -->
<tstamp />
<echo>Initializing the build direcotries!</echo>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<mkdir dir="${build}/lib" />
</target>

<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
<!-- <exclude name="commons-logging-1.1.1.jar" /> -->
</fileset>
</path>

<target name="copy-resources">
<copy todir="${build}">
<fileset dir="${src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="compile" depends="clean, init, copy-resources" description="compile the source ">
<javac srcdir="${src}" destdir="${build}" classpathref="libraries" compiler="javac1.6"/>
</target>

<target name="run" depends="compile" description="run MainDriver ">
<java fork="true" classname="com.test.rss.main.MainDriver" classpathref="libraries" >
<classpath path="${build}" />
</java>
</target>

<target name="dist" depends="compile"
description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib" />
<!-- <copy todir="${dist}/lib">
<fileset dir="${build}/lib">
<include name="**/*.jar" />
</fileset>
</copy>
-->
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/MyProject-${DSTAMP}.jar"
basedir="${build}" />
</target>

<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}" />
<delete dir="${dist}" />
</target>
</project>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 2:02 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
I can not see you set the memory in your java call in your ant file.
Please see following reference how to specify the memory:

http://ant.apache.org/manual/CoreTasks/java.html

<target name="run" depends="compile" description="run MainDriver ">
<java fork="true" classname="com.test.rss.main.MainDriver" classpathref="libraries" >
<classpath path="${build}" />
</java>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 2:58 pm 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
I have modified my ant file as you mentioned, but still it doesn't seem to work (I have tried setting maxmemory with 128m, 256m, 512m and 1024m and it doesn't seem to work), I am still getting the same errors:

<target name="run" depends="compile" description="run MainDriver ">
<java fork="true" classname="com.test.rss.main.MainDriver" classpathref="libraries" maxmemory="1024m" >
<classpath path="${build}" />
</java>
</target>


I had tried setting up intial and max heapsize with ANT_OPTS (Before the max memory change in the build.xml) as well and it didn't seem to affect it either.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 3:05 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
I am sorry, but I can not help further. I am afraid you have to make a memory snapshot right you are running into the problems (run in a profiler environment). I don't know the ant call in detail. Probably you should try spawn and jvmargs as well.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 5:59 pm 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
I tried using jvmargs to specify initial and max heapsize but it also doesn't seem to affect the output. I am puzzled about the fact that it runs well under my eclipse on windows, and anywhere else (windows command prompt, ubuntu terminal window, unbuntu eclipse) it doesn't work. I am running out of ideas, I tried searching on google and it seems there isn't much help out there on this kind of issue :(

In anycase her is my ant file after all the updates suggested so far:


<target name="run" depends="compile" description="run MainDriver ">
<java fork="true" classname="com.test.rss.main.MainDriver" classpathref="libraries" maxmemory="512m" >
<jvmarg value="-Xms512m" />
<jvmarg value="-Xmx512m" />
<classpath path="${build}" />
</java>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 2:24 am 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
Does anybody has any more ideas that I could try??????


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 3:15 pm 
Newbie

Joined: Sun Apr 05, 2009 12:15 am
Posts: 7
I changed my implementation not to use AnnotationConfiguration and instead used Configuration class. and that also throws the same exception. So it seems its not the problem with Annotation per se but with the Configuration class and somehow the error stack trace doesn't provide lot of useful information.

I also tried JAVA_OPTS and that didn't help much either.

It seems the following line where it is creating a new SettingsFactory() in hibernate Configuration.java is throwing that error:

public Configuration() {
this( new SettingsFactory() ); }


Not sure what might be causing this error though.

Any ideas on further to debug this would really help me move forward.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 9:03 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
From the looks of your stack trace I'd say something to do with your logging configuration.


Top
 Profile  
 
 Post subject: Re: OutOfMemory exception initializing AnnotationConfiguration
PostPosted: Tue Aug 04, 2009 6:06 pm 
Newbie

Joined: Tue Aug 04, 2009 6:01 pm
Posts: 4
I'm trying to upgrade my application to hibernate entity manager 3.3.2 from 3.3.0, to seam 2.2 from 2.1, and to jboss 5.x from jboss 4.x and I get this same problem. My best guess is that there is a jar mismatch somewhere...


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