0

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

  • Does this answer your question? [What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?](https://stackoverflow.com/questions/1457863/what-causes-and-what-are-the-differences-between-noclassdeffounderror-and-classn) – Danubian Sailor May 27 '22 at 12:19
  • Thank you Danubian Sailor. I just deleted this project and created new one by following same steps and it worked out. – sravani sravs Jul 29 '22 at 12:57

0 Answers0