3

firends im 使用 netbeans ide 并将其放置在默认 src/java 文件夹中的 hibernate.cfg.xml 但是每当我运行应用程序时,它都会显示以下错误:

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

班级 :

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);
    }
 }
} 
4

1 回答 1

2

采用 :

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

        return sessionFactory;

在这里查看用法。或者直接保持hibernate.cfg.xml直接下src(不推荐)。

于 2012-09-06T08:07:19.040 回答