Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to configure embedded OpenEJB container for tests properly?
    text
    copied!<p>This is my SLSB:</p> <pre><code>@Stateless public class MyService { PersistenceContext(unitName = "abc") EntityManager em; public boolean exists(int id) { return this.em.find(Employee.class, id) != null; } } </code></pre> <p>This is my <code>persistence.xml</code> (I'm using Glassfish v3):</p> <pre><code>&lt;persistence&gt; &lt;persistence-unit name="abc"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;jta-data-source&gt;java:/MyDS&lt;/jta-data-source&gt; &lt;properties&gt; &lt;property name="hibernate.archive.autodetection" value="class" /&gt; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>Now I'm trying to create a test, using OpenEJB embedded container. This is my test class:</p> <pre><code>class MyServiceText { @Test public void testChecksExistence() throws Exception { Properties properties = new Properties(); properties.setProperty( javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory" ); InitialContext ic = new InitialContext(properties); // actual testing skipped } } </code></pre> <p>I would like to use HSQL for testing. How can I instruct OpenEJB that my persistence unit <code>"abc"</code> has to point to HSQL during testing? Shall I create a new version of <code>persistence.xml</code>? Shall I use <code>openejb.xml</code>? I'm lost in their <a href="http://openejb.apache.org/3.0/configuring-persistenceunits-in-tests.html">examples and documentation</a>.. :(</p> <p>It's a Maven-3 project.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload