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