I created a project with following structure:
HibernateUtil:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
Configuration configuration = new Configuration().configure( "C:\\Users\\Nikolay_Tkachev\\workspace\\hiberTest\\src\\logic\\hibernate.cfg.xml");
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();
}
}
at line
Configuration configuration = new Configuration().configure( "C:\\Users\\Nikolay_Tkachev\\workspace\\hiberTest\\src\\logic\\hibernate.cfg.xml");
I have error
Initial SessionFactory creation failed.org.hibernate.HibernateException: C:\Users\Nikolay_Tkachev\workspace\hiberTest\src\logic\hibernate.cfg.xml not found Exception in thread "main" java.lang.ExceptionInInitializerError at logic.HibernateUtil.buildSessionFactory(HibernateUtil.java:19) at logic.HibernateUtil.(HibernateUtil.java:9) at logic.Main.main(Main.java:12) Caused by: org.hibernate.HibernateException: C:\Users\Nikolay_Tkachev\workspace\hiberTest\src\logic\hibernate.cfg.xml not found at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173) at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1947) at org.hibernate.cfg.Configuration.configure(Configuration.java:1928) at logic.HibernateUtil.buildSessionFactory(HibernateUtil.java:14) ... 2 more
What is the reason for the error and how do I fix it?