I need to centralize all the settings for our Java web application in a single .properties file. I can still have hibernate.cfg.xml to add mappings to entity classes, but I need to save all of our database settings and custom paths in a single .properties file.
I originally saved my configs in the hibernate.cfg.xml file as follows.
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.url">my jdbc connection</property> <property name="connection.driver_class">oracle.jdbc.OracleDriver</property> <property name="connection.username">user</property> <property name="connection.password">password</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="hibernate.current_session_context_class">managed</property> <mapping class="myEntityClass"/> </session-factory> </hibernate-configuration>
Now I want to move "connection.url", "connection.username" and "connection.password" to my own .properties file. The code to create my hibernation configuration class came from.
new AnnotationConfiguration().configure();
to
new AnnotationConfiguration() .setProperty("connection.url", databaseUrl) .setProperty("connection.username", databaseUser) .setProperty("connection.password", databasePassword) .configure();
It seemed conceptually simple. Unfortunately, I get the following error when trying to use a Hibernate session that worked with the previous configuration.
User must provide JDBC connection
Any ideas? It seems to me that when Hibernate sees that these properties are not in the hibernate.cfg.xml file, it is assumed that all settings will be added manually and generally ignore xml.
source share