I am writing a javaEE application, using hibernate. The application will be running on multiple environments (dev, qa, prod etc.) & will have separate dbs's associated with each of them. I would like to set the hibernate properties like jdbc-url, username , password etc. separately for each of these environments.
My current persistence.xml
looks like :
<persistence-unit name="PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<validation-mode>CALLBACK</validation-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
<property name="hibernate.event.merge.entity_copy_observer" value="allow"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@host/schema"/>
<property name="hibernate.connection.username" value="abc"/>
<property name="hibernate.connection.password" value="***"/>
</properties>
</persistence-unit>
I am using the persistence unit as follows in my java code:
@PersistenceContext(unitName = "PU")
private EntityManager em;
Is there a way that I can inject the hibernate properties, which are stored in separate properties files, into EntityManager for different environments ?
Please note that I am using JTA and hence cannot use EntityManagerFactory. Also I am not & do not want to use spring.