Brahma Krish
Brahma Krish

Reputation: 51

Initial SessionFactory creation failed in hibernate error

firends i m using netbeans ide and its placed hibernate.cfg.xml in default src/java folder but whenever i run the application its displayed below error :

Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found

class :

public class myutil {
 private static final SessionFactory sessionFactory = buildsf(); 
 public static SessionFactory buildsf() { 
    try {
      // Create the SessionFactory from standard (hibernate.cfg.xml)
      return new Configuration().configure("config/hibernate.cfg.xml").buildSessionFactory();
    } catch (Throwable ex) { // Log the exception.
      System.err.println("Initial SessionFactory creation failed." + ex);
      throw new ExceptionInInitializerError(ex);
    }
 }
} 

Upvotes: 3

Views: 4625

Answers (1)

Nandkumar Tekale
Nandkumar Tekale

Reputation: 16158

Use :

 SessionFactory sessionFactory = new Configuration()
        .configure("config/hibernate.cfg.xml") // give path to hibernate.cfg.xml (recommended)
        .buildSessionFactory();

        return sessionFactory;

Check here usage. Or directly keep hibernate.cfg.xml directly under src(not recommended).

Upvotes: 2

Related Questions