Hi,
I'm new to Hibernate, and I'm trying unsuccessfully to run this simple example in Eclipse:
Code:
package com.example.hibernateexample;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateExample {
public static void main(String[] args) {
Session session = null;
try
{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
//Create new instance of Employee and set values in it by reading them from form object
System.out.println("Inserting Record");
Employee employee = new Employee();
employee.setFirstname("John");
employee.setLastname("Smith");
session.save(employee);
System.out.println("Done");
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
System.out.println("GOT TO FINALLY{}");
// Actual employee insertion will happen at this step
try
{
session.flush();
session.close();
}
catch (Exception e)
{
System.out.println("SESSION FLUSH/CLOSE EXCEPTION");
System.out.println(e.getMessage());
}
}
}
}
This is what I get in the console when I run it:
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/LevelGOT TO FINALLY{}
SESSION FLUSH/CLOSE EXCEPTION
null
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:189)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:112)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:105)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:235)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:208)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:221)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at com.example.hibernateexample.HibernateExample.main(HibernateExample.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at sun.misc.Launcher$ExtClassLoader.findClass(Launcher.java:229)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 8 more
Any help would be greatly appreciated. Thanks.