title: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName HorizonPU with Arquillian
body: <p>I hope someone can help me with an extremely frustrating issue. </p>
  
  <p>I want to use Arquillian to test a webapp I am developing and I am having a hard time trying to get the JPA tests to run. I am pretty new to Arquillian and I must admit that I find it very tricky to use. </p>
  
  <p>My test case is as follows:</p>
  
  <pre><code>  @RunWith(Arquillian.class)
  public class BudgetFacadeTest
  {
      @Deployment
      public static WebArchive deploy(){
          WebArchive archive =  ShrinkWrap.create(WebArchive.class, "testarchive.war")
                  .addClasses(Budget.class, BudgetLine.class, BudgetSection.class, BudgetFacade.class)
                  .addAsManifestResource("META-INF/persistence.xml", "persistence.xml")
                  .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
          System.out.println(archive.toString(true));
          return archive;
      }
  
      @EJB
      BudgetFacade instance; 
  
  
          @Test
      public void testArquillianWorking(){
          instance.count();
      }
      }
  </code></pre>
  
  <p>which is pretty straightforward. The persistence unit is in a separate test folder, and is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
      &lt;persistence-unit name="HorizonPU" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;jdbc/horizonBase&lt;/jta-data-source&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/&gt;
              &lt;property name="eclipselink.logging.level.sql" value="FINE"/&gt;
              &lt;property name="eclipselink.logging.parameters" value="true"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The shrinkwrapped archive structure is as follows:</p>
  
  <pre><code>testarchive.war:
  /WEB-INF/
  /WEB-INF/classes/
  /WEB-INF/classes/com/
  /WEB-INF/classes/com/macraeanddick/
  /WEB-INF/classes/com/macraeanddick/marketinghorizon/
  /WEB-INF/classes/com/macraeanddick/marketinghorizon/company/
  /WEB-INF/classes/com/macraeanddick/marketinghorizon/company/Budget.class
  /WEB-INF/classes/com/macraeanddick/marketinghorizon/company/BudgetSection.class
  /WEB-INF/classes/com/macraeanddick/marketinghorizon/company/BudgetLine.class
  /WEB-INF/classes/com/macraeanddick/facades/
  /WEB-INF/classes/com/macraeanddick/facades/BudgetFacade.class
  /META-INF/
  /META-INF/beans.xml
  /META-INF/persistence.xml
  </code></pre>
  
  <p>Which I believe is all in order, and the POM is as follows:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.arquillian.junit&lt;/groupId&gt;
          &lt;artifactId&gt;arquillian-junit-container&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;        
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.main.extras&lt;/groupId&gt;
          &lt;artifactId&gt;glassfish-embedded-all&lt;/artifactId&gt;
          &lt;version&gt;4.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.arquillian.container&lt;/groupId&gt;
          &lt;artifactId&gt;arquillian-glassfish-embedded-3.1&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.CR4&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.shrinkwrap&lt;/groupId&gt;
          &lt;artifactId&gt;shrinkwrap-impl-base&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.10&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;        
  &lt;/dependencies&gt;
  
  &lt;!--Arquillian Dependency BOMs --&gt;
  &lt;dependencyManagement&gt;
      &lt;dependencies&gt;        
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.arquillian&lt;/groupId&gt;
              &lt;artifactId&gt;arquillian-bom&lt;/artifactId&gt;
              &lt;version&gt;1.1.5.Final&lt;/version&gt;
              &lt;type&gt;pom&lt;/type&gt;
              &lt;scope&gt;import&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/dependencyManagement&gt;
  
  &lt;build&gt;
      &lt;testResources&gt;
          &lt;testResource&gt;
              &lt;directory&gt;src/test/resources&lt;/directory&gt;
          &lt;/testResource&gt;
          &lt;testResource&gt;
              &lt;directory&gt;src/test/resources-glassfish-embedded&lt;/directory&gt;
          &lt;/testResource&gt;
      &lt;/testResources&gt;
  </code></pre>
  
  <p>and yet if I run the test, I get the following:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName HorizonPU
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.getCriteriaBuilder(EntityManagerWrapper.java:834)
      at com.macraeanddick.facades.AbstractFacade.count(AbstractFacade.java:57)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
      at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
      at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
      at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
      at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
      ... 108 more
  </code></pre>
  
  <p>I have absolutely no idea what I am doing wrong and have wasted a day on this already. Any advice would be greatly appreciated!</p>