I need to use multiply persistence units with different properties (in my case MySQL and Oracle database). In persistence.xml I define two different "persistence-unit"s and list only the entity classes there.
Properties could be set in persitence.xml with
<properties>
<property name="..." value="..." />
...
Im doing it in a java class before creating the EntityManager, because I must use different properties (which I read before):
EntityManagerFactory factory;
...
HashMap<String, String> dbProperties = new HashMap<String, String>();
dbProperties.put("javax.persistence.jdbc.driver", driver);
dbProperties.put("javax.persistence.jdbc.url", url);
dbProperties.put("javax.persistence.jdbc.user", user);
dbProperties.put("javax.persistence.jdbc.password", password);
dbProperties.put("eclipselink.ddl-generation", "none");
dbProperties.put("eclipselink.ddl-generation.output-mode", "database");
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, dbProperties);
EntityManager em = factory.createEntityManager();
...
For Oracle I need to set schema dynamicly (if possible) and not hardcoded in @Table annotation in each Entity class.
For now I am using a constant (means it is not dynamicly)
@Table(name="MYTABLE", schema = Constants.ORACLE_SCHEMA)
I want to use
@Table(name="MYTABLE")
And set the schema as property
dbProperties.put(...)
Is there such a property?
On my search I found a syntax which could help
ALTER SESSION SET CURRENT_SCHEMA=MYSCHEMA
But I don't know how to combine it with EntityManager.
I have allready asked about all available properties here, but could not find anything yet.
Thank you in advance.