Reputation: 5542
What would be the proper way to override EclipseLink persistence.xml
property when running application on Glassfish application server?
We need some properties to be configured in a separate configuration file which would be available to a client.
I didn't find any EclipseLink-specific classes which accept some user properties. I only found Glassfish PersistenceUnitLoader class which could be tweaked in order to achieve that. But this would be an ugly hack :)
Upvotes: 0
Views: 889
Reputation: 13857
You can create your own EntityManager at runtime:
Map map = new HashMap();
map.put("javax.persistence.jdbc.password", "password");
map.put("javax.persistence.jdbc.user", "root");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyPU",map);
EntityManager em = emf.createEntityManager(map);
Some eclipselink property names:
<property name="eclipselink.target-database" value="DERBY"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/02DB;create=true"/>
<property name="eclipselink.jdbc.user" value="user"/>
<property name="eclipselink.jdbc.password" value="password"/>
Upvotes: 3