Search code examples
javadatabasehibernatedevelopment-environmentproduction-environment

Hibernate - Prod vs Dev


in my application i am using a command line jvm argument to differentiate whether I am running in production or development. Based on this i proceed to use the relevant configuration / properties files for accessing different databases etc.

With hibernate we have the hibernate.cfg.xml file with the property

<property name="hibernate.connection.url">url</property>

How can we differentiate two different url's for this to avoid connecting to production in dev and visa versa.

Thanks


Solution

  • As someone already mentioned, the RIGHT way to go is to define the datasources inside the application server and expose them through JNDI names.

    If going the right way is not an option and you're using Maven, you could get a workaround with maven resource filtering.

    Take a look at the spec: here