-->
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.  [ 1 post ] 
Author Message
 Post subject: NoClassDefFoundError: /org/apache/log4j/Level
PostPosted: Thu Jan 27, 2011 6:54 pm 
Newbie

Joined: Thu Jan 27, 2011 6:27 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.