Hibernate tutorial problem
I am getting the following error when I try to run the Hibernate
tutorial code below:
HERE1
HERE2
Initial SessionFactory creation failed.java.lang.NoSuchFieldError:
name
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at events.EventManager.createAndStoreEvent(EventManager.java:50)
at events.EventManager.main(EventManager.java:18)
Caused by: java.lang.NoSuchFieldError: name
at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:
75)
at
org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:
75)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 2 more
Hibernate.java:
package util;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new
Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be
swallowed
System.err.println("Initial SessionFactory creation
failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
EventManager.java:
package events;
import org.hibernate.Session;
import java.util.List;
import java.util.Date;
import util.HibernateUtil;
public class EventManager {
public static void main(String[] args) {
EventManager mgr = new EventManager();
System.out.println("HERE1");
if (args[0].equals("store")) {
System.out.println("HERE2");
mgr.createAndStoreEvent("My Event", new Date());
System.out.println("HERE3");
}
}
I am running this code in Eclipse and was originally thinking it was a
problem with the log4j.properties file, but I can't figure out what
the problem is.
Your help is appreciated.
Bill