0
我在Jboss AS 7.1.1上部署了EAR文件。在jboss 7上找不到Hibernate.cfg.xml
在其中一個EJB項目中,我們在META-INF文件夾下有一個persistence.xml文件。我需要做一個數據庫中的批量更新,所以我寫了這個代碼,得到一個會話工廠:
private SessionFactory buildSessionFactory() throws Exception {
SessionFactory factory = null;
try{
Configuration configuration = new Configuration();
configuration.addResource("/META-INF/persistence.xml");
configuration.configure().setProperty("hibernate.show_sql", "false"); ---> **throws error**
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
factory = configuration.buildSessionFactory(serviceRegistry);
}
catch (Throwable t){
throw new Exception(t);
}
return factory;
}
的問題是我得到:org.hibernate.HibernateException: /hibernate.cfg.xml not found
。
我該如何告訴休眠使用persistence.xml
而不是hibernate.cfg.xml
?
UPDATE:
我發現我使用了錯誤的方法:
configuration.addResource("/META-INF/persistence.xml");
應該是:
configuration.configure("/META-INF/persistence.xml");
但現在我有一個不同的問題,因爲Jboss的持久性.xml與hibernate.cfg.xml沒有相同的結構,所以我得到無效的配置異常。
任何想法什麼是正確的路線在這裏?
取代更新,你可以回答你的問題,甚至接受它。所以將來它可能對其他人有幫助。 – 2012-08-02 10:43:59