BackgroundWe have old database code (Hibernate 3.2.4.ga) that would manually create session factories with application configurable settings like this:
Code:
Configuration hibernateConfiguration =
new Configuration().configure( hibernateConfigurationUrl )
.setProperty( "hibernate.connection.driver_class", JDBC_DRIVERCLASS )
.setProperty( "hibernate.connection.url", JDBC_URL )
.setProperty( "hibernate.connection.username", JDBC_USERNAME )
.setProperty( "hibernate.connection.password", JDBC_PASSWORD )
.setProperty( "hibernate.dialect", HIBERNATE_DIALECT );
This code was used in OSGi (Apache Felix). We are updating to a newer OSGi platform, Apache Karaf 3.0.1. I am attempting to update our software to use a newer hibernate (4.3.1.Final) in order to move things closer to doing things the 'right way' in OSGi with hibernate. In order to not have to rewrite all of our database code to use JPA, we would like to use unmanaged native hibernate mode in OSGi. I know in OSGi unmanaged native mode, you are supposed to access the session factory with osgi services, but in that case, the session factory is already created with the configuration in the jar.
The ProblemThe problem I am trying to figure out has to do with configuring hibernate with one or more hibernate.cfg.xml files. The examples I see embed the connection information right in the hibernate.cfg.xml that gets put in the jar. I would rather not have our database connection information hardcoded right in the jar, and would rather it be something we can have in configuration files that gets pulled in. Is there a way to support this with hibernate osgi in unmanaged native mode?
I would like the following to be able to be set by my software, not by a 'hardcoded' xml file in the jar:
Code:
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/mydbname</property>
<property name="hibernate.connection.username">mydbuser</property>
<property name="hibernate.connection.password">mydbpass</property>
It would even be okay for the hibernate.cfg.xml to be loaded seperately from the jar, but I just have not been able to figure out a way to do that. Any help would be appreciated.
Thanks!