3

firends im は netbeans ide を使用し、hibernate.cfg.xml をデフォルトの src/java フォルダーに配置しましたが、アプリケーションを実行するたびにエラーの下に表示されます:

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 に答える