You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Support WebAlertPro <su...@webalertpro.com> on 2011/05/02 14:52:14 UTC

How to override a property in persistence.xml

I have the following property in persistence.xml :

<property name="openjpa.ConnectionProperties"
value="DriverClassName=com.mysql.jdbc.Driver,jdbcUrl=jdbc:mysql://localhost:3306/c,user=foo,password=foo,autocommit=false,automaticTestTable=testtable,idleConnectionTestPeriod=60"/>


I am trying to override this via a system property, so I have set:

-Dopenjpa.ConnectionProperties=DriverClassName=com.mysql.jdbc.Driver,jdbcUrl=jdbc:mysql://localhost:3306/bar,user=bar,password=bar,autocommit=false,automaticTestTable=testtable,idleConnectionTestPeriod=60

This doesn't seem to work though. OpenJPA always seems to read the
property set in persistence.xml
Only if the property in persistence.xml is NOT SET does it then read the
value from system property.

Is this expected behaviour? If so what's the correct way to override a
property?

 - Joel

Re: How to override a property in persistence.xml

Posted by Joel Halbert <jo...@su3analytics.com>.
Gotcha, thanks for for clarifying.

On Mon, 2011-05-02 at 10:35 -0700, Jim O'Rourke wrote:
> The way OpenJPA bootstraps, persistence.xml wins over System.properties.
> 
> Pass a map like so Persistence.createEntityManagerFactory("your_pu_name",
> propertyOveridesMap).
> 
> If you need to override for say test versus production, you can move your
> properties from persistence.xml to openjpa.xml, see 
> http://openjpa.apache.org/builds/2.0.1/apache-openjpa-2.0.1/docs/manual/ref_guide_conf_specify.html
> http://openjpa.apache.org/builds/2.0.1/apache-openjpa-2.0.1/docs/manual/ref_guide_conf_specify.html 
> 
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/How-to-override-a-property-in-persistence-xml-tp6324365p6324624.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.



Re: How to override a property in persistence.xml

Posted by Jim O'Rourke <ji...@gmail.com>.
The way OpenJPA bootstraps, persistence.xml wins over System.properties.

Pass a map like so Persistence.createEntityManagerFactory("your_pu_name",
propertyOveridesMap).

If you need to override for say test versus production, you can move your
properties from persistence.xml to openjpa.xml, see 
http://openjpa.apache.org/builds/2.0.1/apache-openjpa-2.0.1/docs/manual/ref_guide_conf_specify.html
http://openjpa.apache.org/builds/2.0.1/apache-openjpa-2.0.1/docs/manual/ref_guide_conf_specify.html 

--
View this message in context: http://openjpa.208410.n2.nabble.com/How-to-override-a-property-in-persistence-xml-tp6324365p6324624.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.