我需要配置hibernate以從karaf上的OSGI捆綁包上的自定義位置加載hibernate.cfg.xml。我需要能夠在不編輯JAR文件的情況下編輯配置,這似乎是唯一可用的選項。我正在使用以下類來加載Hibernate SessionFactory,如hibernate文檔中所述,但似乎無法在Hibernate OSGI模塊公開的此服務返回的SessionFactory上對其進行配置。我一直在研究這個問題幾天,但我找不到解決方案。我正在使用Hibernate 4.3.11.Final。任何幫助非常感謝,謝謝在KARAF OSGI Bundle上定製hibernate.cfg.xml位置
公共類的HibernateUtil {
private static SessionFactory sf;
public static Session getSession() {
return getSessionFactory().openSession();
}
private static SessionFactory getSessionFactory() {
if (sf == null) {
Bundle thisBundle = FrameworkUtil.getBundle(HibernateUtil.class);
BundleContext context = thisBundle.getBundleContext();
ServiceReference sr = context.getServiceReference(SessionFactory.class.getName());
sf = (SessionFactory) context.getService(sr);
}
return sf;
}
我使用Hibernate 4.3.11.Final –