Hi,
I am newbie to Hibernate. I wanted to run a simple hibernate example from the Java Persistence with Hibernate. This helloworld-native works fine with ant build tool. when i try to use the Hibernate IDE, i get the below stack trace.
I have googled and tried searching for the mistake i have done. The hibernate IDE doesnt have a runnable example for Eclipse.
The stack trace is,
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ExceptionInInitializerError
at persistence.HibernateUtil.<clinit>(HibernateUtil.java:21)
at hello.HelloWorld.main(HelloWorld.java:16)
Caused by: java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:168)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:187)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:191)
at persistence.HibernateUtil.<clinit>(HibernateUtil.java:18)
... 1 more
Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:529)
... 5 more
The hibernate cfg file is same as the one provided in the Message Example.,
Code:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- SQL to stdout logging
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
-->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping resource="hello/Message.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The Hibernate Util .java is
Code:
package persistence;
import java.io.File;
import org.hibernate.*;
import org.hibernate.cfg.*;
/**
* Startup Hibernate and provide access to the singleton SessionFactory
*/
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static Configuration config;
static {
try {
config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
// Alternatively, we could look up in JNDI here
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}
I can feel that this should be my mistake somewhere. But i wonder that i couldnt find any post talking about this particular minor problem.
Regards,