title: Playframework 2.2.x + Java +JPA - Separate Database for Unit Testing and Production
body: <p>I am using Java + Playframework + JPA using PlayFramework 2.3-M1 for developing application. </p>
  
  <p>I want to use MySQL database when I run the aplication, but when I run test using</p>
  
  <pre><code>activator test
  </code></pre>
  
  <p>I want to use in memory database H2.</p>
  
  <p>How can this be done ?</p>
  
  <p>Below is my </p>
  
  <p>conf/META-INF/persistence.xml</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
               http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0"&gt;
  
      &lt;persistence-unit name="prod" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;non-jta-data-source&gt;prodDS&lt;/non-jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" 
                        value="org.hibernate.dialect.MySQL5Dialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
              &lt;property name="hibernate.show_sql" value="true"&gt;&lt;/property&gt;
              &lt;property name="hibernate.format_sql" value="true"&gt;&lt;/property&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  
      &lt;persistence-unit name="test" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;non-jta-data-source&gt;TestDS&lt;/non-jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" 
                        value="org.hibernate.dialect.H2Dialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
              &lt;property name="hibernate.show_sql" value="true"&gt;&lt;/property&gt;
              &lt;property name="hibernate.format_sql" value="true"&gt;&lt;/property&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>conf/application.conf</p>
  
  <pre><code># Database configuration
  # ~~~~~ 
  # You can declare as many datasources as you want.
  # By convention, the default datasource is named `default`
  #
  db.test.driver=org.h2.Driver
  db.test.url="jdbc:h2:mem:play"
  db.test.user=sa
  db.test.password=""
  
  db.test.jndiName=TestDS
  
  jpa.test=testPersistenceUnit
  
  db.default.driver=com.mysql.jdbc.Driver
  db.default.url="jdbc:mysql://X.X.X.X/lb"
  db.default.user=lb
  db.default.password="lb"
  
  #
  # You can expose this datasource via JNDI if needed (Useful for JPA)
  db.default.jndiName=DefaultDS
  
  
  jpa.default=defaultPersistenceUnit
  
  
  # Evolutions
  # ~~~~~
  # You can disable evolutions if needed
  evolutionplugin=disabled
  
  # Ebean configuration
  # ~~~~~
  # You can declare as many Ebean servers as you want.
  # By convention, the default server is named `default`
  #
  ebean.default="models.*"
  </code></pre>
  
  <p>Is this the best approach to get it done?</p>
  
  <p>Thanks</p>