Joel Joel -3 years ago 164
Java Question

How to override persistence.xml properties in OpenJPA

I have the following property in my persistence.xml :

<property name="openjpa.ConnectionProperties"

I am trying to override it using a system property, as per the docs, so I have set:


But it doesn't work: OpenJPA always reads the property value from persistence.xml

Only when the property in persistence.xml is removed does it read the value from the system property.

Is this expected behaviour and if so what's the correct way to override a property from persistence.xml?

Answer Source

OpenJPA doesn't look at SystemProperties by default when creating an EM/EMF. Try passing in System.getProperties() in when creating your EMF.

Persistence.createEntityManagerFactory("pu_Name", System.getProperties());

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download