【发布时间】:2017-07-01 18:13:42
【问题描述】:
我需要配置 hibernate 以从 karaf 的 OSGI 包上的自定义位置加载 hibernate.cfg.xml。我需要能够在不编辑 JAR 文件的情况下编辑配置,这似乎是唯一可用的选项。我正在使用以下类来加载 Hibernate SessionFactory,如休眠文档中所述,但似乎无法在 Hibernate OSGI 模块返回的 SessionFactory 上配置此服务。我一直在研究这个问题好几天,但我找不到解决方案。我正在使用 Hibernate 4.3.11.Final。非常感谢任何帮助,谢谢
公共类 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