我创建了一个具有以下结构的项目:
休眠实用程序:
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();
}
}
在线
Configuration configuration = new Configuration().configure( "C:\\Users\\Nikolay_Tkachev\\workspace\\hiberTest\\src\\logic\\hibernate.cfg.xml");
我有错误
初始 SessionFactory 创建 failed.org.hibernate.HibernateException: C:\Users\Nikolay_Tkachev\workspace\hiberTest\src\logic\hibernate.cfg.xml 在 logic.HibernateUtil.buildSessionFactory 的线程“main”java.lang.ExceptionInInitializerError 中找不到异常(HibernateUtil.java:19) 在 logic.HibernateUtil.(HibernateUtil.java:9) 在 logic.Main.main(Main.java:12) 引起: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) 在 logic.HibernateUtil.buildSessionFactory(HibernateUtil.爪哇:14)... 2更多
错误的原因是什么,我该如何解决?