Dynamic EntityManager & EntityManagerFactory & Oracle wallet
public JPAUtil(String config) throws Exception {
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:oci:/@" + config;
Map properties = new HashMap();
// Mixed versions of Eclipselink require different versions of params.
properties.put(PersistenceUnitProperties.JDBC_DRIVER, "oracle.jdbc.OracleDriver");
properties.put("eclipselink.jdbc.driver", "oracle.jdbc.OracleDriver");
properties.put(PersistenceUnitProperties.JDBC_URL, url);
properties.put("eclipselink.jdbc.url", url);
// Remark that we had to specify the parameters twice.
// Newer versions of Eclipselink are standardize on parameters like in javax.persistence.xxxx
// older versions require parameters as eclipselink.jdbc.url
properties.put(PersistenceUnitProperties.JDBC_USER, "");
System.out.println(PersistenceUnitProperties.JDBC_URL);
properties .put(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN, "1");
properties.put(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN, "1");
properties.put(PersistenceUnitProperties.LOGGING_LEVEL, "OFF");
properties.put(PersistenceUnitProperties.TARGET_DATABASE, "Oracle");
properties.put(PersistenceUnitProperties.TARGET_SERVER, "NONE");
properties.put(PersistenceUnitProperties.WEAVING, "static");
emf = Persistence.createEntityManagerFactory("DSLocalDynamic", properties);
if (emf.isOpen()) {
System.out.println("emf is open");
Map props2 = new HashMap();
props2.put(PersistenceUnitProperties.SESSION_NAME, "monimir");
props2.put(PersistenceUnitProperties.JDBC_DRIVER, "oracle.jdbc.OracleDriver");
props2.put(PersistenceUnitProperties.TRANSACTION_TYPE, "RESOURCE_LOCAL");
// to override data source if one is specified in persistence.xml
props2.put(PersistenceUnitProperties.JTA_DATASOURCE, "");
// to override data source if one is specified in persistence.xml
props2.put(PersistenceUnitProperties.JDBC_URL, url);
props2.put(PersistenceUnitProperties.JDBC_USER, "");
props2.put( PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN, "1");
props2.put( PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN, "1");
props2.put(PersistenceUnitProperties.LOGGING_LEVEL, "FINE");
props2 .put(PersistenceUnitProperties.TARGET_DATABASE, "Oracle");
props2.put(PersistenceUnitProperties.TARGET_SERVER, "NONE");
props2.put(PersistenceUnitProperties.WEAVING, "static");
EntityManager em = emf.createEntityManager(props2);
if (em.isOpen()) {
em.close(); }
} else {
System.out.println("em is not open"); }
}