You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "hanasaki@gmail.com" <ha...@gmail.com> on 2014/11/19 05:35:18 UTC

Testing Best practices - JPA persistence.xml different between Arquillian JUnit test and deploy in Production

The question is: "how can the persistence.xml, which is generally 
included in the same JAR as the JPA domain objects and DAO related code 
(ie: classes that use entity manager) be configured to handle different 
database servers"

There are two scenarios for this:
1. testing - currently thinking that Arquillian will handle this by 
deleting the persistence.xml and adding a testing specific one when the 
WAR is built as part of the unit test - Other ideas / suggestions?
2. run-time - for example the WAR is provided to several customers.  One 
customer runs Oracle and the other runs mysql.

==
Generally planning to use either H2 or HSQLDB (maybe in memory) for JPA 
based testing and another DB in production (MySQL, PostgreSQL, Oracle)

Changing the datasource independently of the JAR or Code is quite easy 
in a JEE container.  However the persistence.xml is generally tailored 
to a specific DB (see below) which creates the issue.

ex:
	<provider>...
	<property> various... probably can add for multiple DB's
		and those that do not apply will be ignored.
	hibernate.dialect
	org.hibernate.dialect

Re: Testing Best practices - JPA persistence.xml different between Arquillian JUnit test and deploy in Production

Posted by jieryn <ji...@gmail.com>.
I'd recommend using Apache Maven to build, test, and deploy your
application. Then you can just have
src/main/webapp/META-INF/persistence.xml for your production
persistence.xml, and src/test/resources/META-INF/persistence.xml as
your test persistence.xml, and finally your
src/test/java/MyArqTest.java you simply add a
MetaInf("META-INF/persistence.xml") which will pick up the
src/test/resources flavor because of the way Maven orders the
classpath for each lifecycle phase.

On Tue, Nov 18, 2014 at 11:35 PM, hanasaki@gmail.com <ha...@gmail.com> wrote:
> The question is: "how can the persistence.xml, which is generally included
> in the same JAR as the JPA domain objects and DAO related code (ie: classes
> that use entity manager) be configured to handle different database servers"
>
> There are two scenarios for this:
> 1. testing - currently thinking that Arquillian will handle this by deleting
> the persistence.xml and adding a testing specific one when the WAR is built
> as part of the unit test - Other ideas / suggestions?
> 2. run-time - for example the WAR is provided to several customers.  One
> customer runs Oracle and the other runs mysql.
>
> ==
> Generally planning to use either H2 or HSQLDB (maybe in memory) for JPA
> based testing and another DB in production (MySQL, PostgreSQL, Oracle)
>
> Changing the datasource independently of the JAR or Code is quite easy in a
> JEE container.  However the persistence.xml is generally tailored to a
> specific DB (see below) which creates the issue.
>
> ex:
>         <provider>...
>         <property> various... probably can add for multiple DB's
>                 and those that do not apply will be ignored.
>         hibernate.dialect
>         org.hibernate.dialect

Re: Testing Best practices - JPA persistence.xml different between Arquillian JUnit test and deploy in Production

Posted by rmpestano <rm...@gmail.com>.
i didnt knew about romain's idea but a i think a bit of maven properties
can help:
https://github.com/rmpestano/cdi-crud/blob/master/src/test/resources/persistence.xml

in my case i change the properties via maven profile.

maybe it helps.

2014-11-19 5:01 GMT-02:00 Romain Manni-Bucau [via TomEE & OpenEJB] <
ml-node+s979440n4672931h34@n4.nabble.com>:

> Hi
>
> The datasource is by spec indirect in EE so no issues here. Then with most
> providers system properties are read as persistence unit properties.
> Finally in TomEE you can set PERSISTENCEUNIT.<unit name>.<key>=<value> in
> tomee properties including system properties.
> Le 19 nov. 2014 05:36, "[hidden email]
> <http://user/SendEmail.jtp?type=node&node=4672931&i=0>" <[hidden email]
> <http://user/SendEmail.jtp?type=node&node=4672931&i=1>> a écrit :
>
> > The question is: "how can the persistence.xml, which is generally
> included
> > in the same JAR as the JPA domain objects and DAO related code (ie:
> classes
> > that use entity manager) be configured to handle different database
> servers"
> >
> > There are two scenarios for this:
> > 1. testing - currently thinking that Arquillian will handle this by
> > deleting the persistence.xml and adding a testing specific one when the
> WAR
> > is built as part of the unit test - Other ideas / suggestions?
> > 2. run-time - for example the WAR is provided to several customers.  One
> > customer runs Oracle and the other runs mysql.
> >
> > ==
> > Generally planning to use either H2 or HSQLDB (maybe in memory) for JPA
> > based testing and another DB in production (MySQL, PostgreSQL, Oracle)
> >
> > Changing the datasource independently of the JAR or Code is quite easy
> in
> > a JEE container.  However the persistence.xml is generally tailored to a
> > specific DB (see below) which creates the issue.
> >
> > ex:
> >         <provider>...
> >         <property> various... probably can add for multiple DB's
> >                 and those that do not apply will be ignored.
> >         hibernate.dialect
> >         org.hibernate.dialect
> >
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://tomee-openejb.979440.n4.nabble.com/Testing-Best-practices-JPA-persistence-xml-different-between-Arquillian-JUnit-test-and-deploy-in-Pron-tp4672930p4672931.html
>  To start a new topic under TomEE Users, email
> ml-node+s979440n979441h44@n4.nabble.com
> To unsubscribe from TomEE Users, click here
> <http://tomee-openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=979441&code=cm1wZXN0YW5vQGdtYWlsLmNvbXw5Nzk0NDF8MTE1OTM0ODgyNg==>
> .
> NAML
> <http://tomee-openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



-- 
<http://www.advancedit.com.br/>Att,

Rafael M. Pestano

Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
Graduando em Ciência da Computação UFRGS
http://conventionsframework.org <http://conventions.github.io/home/>
http://rpestano.wordpress.com/
@realpestano




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Testing-Best-practices-JPA-persistence-xml-different-between-Arquillian-JUnit-test-and-deploy-in-Pron-tp4672930p4672939.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Testing Best practices - JPA persistence.xml different between Arquillian JUnit test and deploy in Production

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

The datasource is by spec indirect in EE so no issues here. Then with most
providers system properties are read as persistence unit properties.
Finally in TomEE you can set PERSISTENCEUNIT.<unit name>.<key>=<value> in
tomee properties including system properties.
Le 19 nov. 2014 05:36, "hanasaki@gmail.com" <ha...@gmail.com> a écrit :

> The question is: "how can the persistence.xml, which is generally included
> in the same JAR as the JPA domain objects and DAO related code (ie: classes
> that use entity manager) be configured to handle different database servers"
>
> There are two scenarios for this:
> 1. testing - currently thinking that Arquillian will handle this by
> deleting the persistence.xml and adding a testing specific one when the WAR
> is built as part of the unit test - Other ideas / suggestions?
> 2. run-time - for example the WAR is provided to several customers.  One
> customer runs Oracle and the other runs mysql.
>
> ==
> Generally planning to use either H2 or HSQLDB (maybe in memory) for JPA
> based testing and another DB in production (MySQL, PostgreSQL, Oracle)
>
> Changing the datasource independently of the JAR or Code is quite easy in
> a JEE container.  However the persistence.xml is generally tailored to a
> specific DB (see below) which creates the issue.
>
> ex:
>         <provider>...
>         <property> various... probably can add for multiple DB's
>                 and those that do not apply will be ignored.
>         hibernate.dialect
>         org.hibernate.dialect
>