I have several different databases for different environments to connect my application to. These are constant per installation but differ between them. In other words there is
Hibernate is used via Annotations and the code doesn't 'know' which environment it's run in. All the databases are mySQL driven but differ in url, username and password.
Currently I removed the hibernate.cfg.xml from the application and moved it to the home directory of the application-server-user but this doesn't seem like a very good solution for security reasons and because this introduced the need to manually update any changed mappings when updating an environment.
I really hope, there is a better solution but I can't find one.
You can bundle the hibernate.cfg.xml in a .jar or you could use a JPA (persistence.xml) approach instead which allows you to have different "persistence units" that you can then choose based on any variable you'd like (a properties file in your home for example). See http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/configuration.html#setup-configuration-packaging for an example of a persistence.xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With