openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: making properties in persistence.xml dynamic
Date Fri, 01 Apr 2011 02:04:35 GMT
The schema property is not used at compile time.

The easiest way to use a different schema is to use a jta-data-source in
your persistence.xml and set the appropriate schema on the datasource. I
think WebSphere allows the schema to be set as a custom property for their
datasources.

Will the schema be different for each server, or just different between dev
and production? If there are only a few values, you could create a
persistence unit for each schema, inject both contexts, and have the
application determine which one to use (kind of ugly).

Setting the property at EMF creation is also an option (it can be passed in
the property map AFAIK) - so long as you get the value before injection
occurs (or create the EMF yourself). An EntityManager created in this way
will use PersistenceContextType=extended. The application will also have to
be diligent  about closing the EntityManager when it's done using it.

You cannot, however, set the property when you create an EntityManager -
even if you do not use injection.

Regarding RAD - I suspect they pick up the same version of OpenJPA that WAS
uses. I can't say how often they refresh it though, so it might be a little
behind the snapshots we publish.

Hope this helps, or is at least a starting point.

-mike


On Thu, Mar 31, 2011 at 5:00 PM, areider <openjpa@reider.net> wrote:

> I need to deploy one Enterprise Application Repository (EAR) file across
> multiple Websphere servers, eg a development,test,QA,and production server,
> where the schema name varies depending on the server. This is actually a
> legal or regulatory requirement - the EAR file deployed to production must
> be the same EAR file that was deployed and test in QA, with no intervening
> changes.
>
> For internal frameworks, we generally 'dynamicize' properties in the EAR by
> having a separate named folder the property file for each environment.
> Then,
> runtime startup code can 'select' the  folder based on a JNDI value defined
> on each server. That is not obviously not going to work for JPA and
> persistence.xml. Is the schema property used at compile time? If so, that
> would seem to rule out any possibility of making it dynamic.
>
> I also looked at overriding the persistence.xml properties at runtime, eg
> using an EntityManagerFactory instead of EntityManager injection, which
> allows passing a property map. The problems i hit there, were that the EMF
> method signatures in the documentation for 1.2.3_Snapshot (this is on
> (Eclipse-based) Rad 7.5.5) did not seem to match the code,  plus I could
> not
> figure out what the analog of the PersistenceContextType attribue of the
> @PersistenceContext annotation is when using EMF vs injection; also i was
> not sure if openjpa.jdbc properties could be passed; also I got the
> impression that EM's created using an EMF might not behave in exactly the
> same way as injected ones in terms of the persistenceContextType (eg the
> EMs
> would always be PersistenceContextType=extended?)
>
> Is there any available solution for deploying the same EAR to different
> servers and having JPA pick up a different schema value (and possibly other
> properties) depending on a JNDI value or other value that varies per
> server?
> I read that persistence.xml just has to be on the classpath,  so possibly
> it
> could be external to the EAR, but that could be problematic since not all
> the servers support symlinks (at least one is a windows server).
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/making-properties-in-persistence-xml-dynamic-tp6228861p6228861.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message