Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration Exception

266 Views Asked by At

I am learning Hibernate and tried a simple program. I used Hibernate 5.3 version and added all the Hibernate required .jar files to the build path. I can find the Configuration class in the ref libraries folder, still getting the exception. Is there anything wrong with the hibernate.cfg.xml? Is there any specific location it has to be saved? Please help me. Thanks in advance. I am attaching my project layout and source code.

my HibernateUtil.java code

  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  public class HibernateUtil {
  private static final SessionFactory sessionFactory = 
 buildSessionFactory();

  private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        System.out.println("hii");
        return 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;
 }

 public static void shutdown() {
    // Close caches and connection pools
    getSessionFactory().close();
  }
  }

[Project layout]project layoutHibernate confg xml file

0

There are 0 best solutions below