我需要配置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 –