在OSGi中手动配置Hibernate SessionFactory

时间:2014-10-21 11:54:25

标签: java hibernate osgi sessionfactory

前一段时间我终于设法获得了一个使用Hibernate工作的OSGi服务。 我目前的任务是将此服务更改为托管服务。基本上,我应该在运行时更改我的配置以决定2个数据库,但我不确定如何。我得到了这样的SessionFactory:

ServiceReference<?> ref = context.getServiceReference(SessionFactory.class.getName());
            SessionFactory factory = (SessionFactory) context.getService(ref);

对于我的知识,这是在OSGi中获取SessionFactory的唯一可行方法,但整个配置都在org.hibernate.osgi.OsgiSessionFactoryService完成。

我的问题是,有没有办法手动配置我的SessionFactory,比如更改使用过的hibernate.cfg.xml或使用.setProperty("connection.url", "...")

我能想象的唯一解决方案是使用经过大量修改的OsgiSessionFactoryService,但这似乎有些过分......

有没有人有更优雅的方法解决这个问题?

0 个答案:

没有答案
相关问题