Reputation: 951
There is way to change jta-data-source in persistence.xml on runtime and stay in manage mode
@PersistenceContext(unitName="BookUnit")
private EntityManager em;
(i know i can use EntityManagerFactory but i want to stay in managed mode like i wrote before)
I have more then one environment (local,test,prod)
and for each environment there is different jndi datasource
i don't wont to change the persistence.xml
file for each environment
i want to manage it in the code
Upvotes: 0
Views: 302
Reputation: 2052
There are multiple ways of achieving this kind of functionality -
1) Use environmental variables in persistence.xml and initialize them appropriately based on your environment, i.e., while starting the server init this variable to appropriate value
2) As your instances for dev, test & production would be different, for the same JNDI name configure your datasource appropriately.
Ex: on your dev server configure your datasoruce to connect to dev DB, similarly for test environment to test DB and in production to Production DB.
I would always go with Option 2, as this is standard way of doing things.
Upvotes: 1