new Configuration()new AnnotationConfiguration()默認加載 classpath 下 /hibernate.cfg.xml,實際調用 configure("/hibernate.cfg.xml")。
最常用方式,內部調用 doConfigure(InputStream, String)。資源查找邏輯:
Thread.currentThread().getContextClassLoader()Environment.class.getResourceAsStream()Environment.class.getClassLoader().getResourceAsStream()HibernateException調用 doConfigure(url.openStream(), url.toString())。
調用 doConfigure(new FileInputStream(configFile), configFile.toString())。
使用 dom4j 解析 XML 為 Document,創建 SAXReader 讀取。
直接解析 Document 對象,處理所有配置與 mapping。