I need to be able to store database config properties in src|main|java|dbConnection.properties
and include it to hibernate.cfg.xml
in form of
You can do it programmatically.
hibernate.cfg.xml should be as following.
org.hibernate.transaction.JDBCTransactionFactory
dbConnection.properties
connection.driver_class=org.postgresql.Driver
connection.username=postgres
connection.password=postgres
And when creating the SessionFactory
you can do the following.
Properties dbConnectionProperties = new Properties();
try {
dbConnectionProperties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("dbConnection.properties"));
} catch(Exception e) {
// Log
}
SessionFactory sessionFactory = new Configuration().mergeProperties(dbConnectionProperties).configure().buildSessionFactory();