You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Joel Halbert <jo...@su3analytics.com> on 2011/05/02 15:01:37 UTC

How to override persistence.xml properties

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 persistence.xml properties

Posted by Joel Halbert <jo...@su3analytics.com>.
Rick - I also posted the question to stackoverflow, if you're on SO  and
want to answer the question there I'll mark it as correct:
http://stackoverflow.com/questions/5857828/how-to-override-persistence-xml-properties-in-openjpa

- Joel




On Mon, 2011-05-02 at 15:24 +0100, Joel Halbert wrote:
> Hi Rick,
> 
> Good point, I'm now passing all the sys properties in explicity and it
> works fine.
> 
> Properties props = new Properties();
> props.setProperty("openjpa.Log", "log4j");
>           props.putAll(System.getProperties());
> EntityManagerFactory factory =
> Persistence.createEntityManagerFactory("su3", props);
> 
> 
> Thanks!
> 
> Joel
> 
> 
> 
> 
> On Mon, 2011-05-02 at 08:59 -0500, Rick Curtis wrote: 
> > How are you creating your EM/EMFs?? ... I don't recall if we will look at
> > system properties by default.
> > 
> > If you're using javax.persistence.Persistence you could do something like
> > Persistence.createEntityManagerFactory("pu_Name", System.getProperties());
> > 
> > HTH,
> > Rick
> > 
> > On Mon, May 2, 2011 at 8:01 AM, Joel Halbert <jo...@su3analytics.com> wrote:
> > 
> > > 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 persistence.xml properties

Posted by Joel Halbert <jo...@su3analytics.com>.
Hi Rick,

Good point, I'm now passing all the sys properties in explicity and it
works fine.

	 Properties props = new Properties();
	 props.setProperty("openjpa.Log", "log4j");
          props.putAll(System.getProperties());
	EntityManagerFactory factory =
Persistence.createEntityManagerFactory("su3", props);


Thanks!

Joel




On Mon, 2011-05-02 at 08:59 -0500, Rick Curtis wrote:

> How are you creating your EM/EMFs?? ... I don't recall if we will look at
> system properties by default.
> 
> If you're using javax.persistence.Persistence you could do something like
> Persistence.createEntityManagerFactory("pu_Name", System.getProperties());
> 
> HTH,
> Rick
> 
> On Mon, May 2, 2011 at 8:01 AM, Joel Halbert <jo...@su3analytics.com> wrote:
> 
> > 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 persistence.xml properties

Posted by Rick Curtis <cu...@gmail.com>.
How are you creating your EM/EMFs?? ... I don't recall if we will look at
system properties by default.

If you're using javax.persistence.Persistence you could do something like
Persistence.createEntityManagerFactory("pu_Name", System.getProperties());

HTH,
Rick

On Mon, May 2, 2011 at 8:01 AM, Joel Halbert <jo...@su3analytics.com> wrote:

> 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
>
>
>