title: Error creating EntityManagerFactory when trying to access H2 embedded in-memory database through Hibernate in WebSphere
body: <p>When trying to use H2 embedded in-memory database in WebSphere I'm getting the following error:</p>
  
  <pre><code>EJBException: Injection failure; nested exception is: 
  java.lang.IllegalStateException:
  EntityManagerFactory has not been created for PU : 
  PuId=javaee6-0_0_1-SNAPSHOT_war#javaee6-0.0.1-SNAPSHOT.war#javaee6
  </code></pre>
  
  <p><code>javaee6</code> is the name of my application, which I build to <code>javaee6-0.0.1-SNAPSHOT.war</code> using Maven.</p>
  
  <p>My attempt to deploy H2 on WebSphere was by coping <code>h2-1.3.173.jar</code> to <code>WebSphere\AppServer8\lib</code> and restarting the server.</p>
  
  <p>My WebSphere version is 8.0.0.5.</p>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &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="javaee6" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
  
          &lt;class&gt;com.learning.business.car.Car&lt;/class&gt;
  
          &lt;properties&gt;
              &lt;property name="connection.driver_class" value="org.h2.Driver" /&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
  
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Managed bean:</p>
  
  <pre><code>package com.learning.app.car;
  
  import javax.ejb.EJB;
  import javax.faces.bean.ManagedBean;
  import com.learning.business.car.CarRepo;
  
  @ManagedBean
  public class CarBean {
  
      @EJB
      public CarRepo carRepo;
  
      public Integer getCarsCount() {
          return carRepo.getAll().size();
      }
  }
  </code></pre>
  
  <p>EJB module:</p>
  
  <pre><code>package com.learning.business.car;
  
  import java.util.List;
  import javax.ejb.Stateless;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import javax.persistence.TypedQuery;
  
  @Stateless
  public class CarRepo {
  
      @PersistenceContext
      protected EntityManager em;
  
      public List&lt;Car&gt; getAll() {
  
          TypedQuery&lt;Car&gt; query = em.createQuery("SELECT c FROM Car c", Car.class);
          return query.getResultList();
      }
  }
  </code></pre>
  
  <p>Entity:</p>
  
  <pre><code>package com.learning.business.car;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  @Entity
  public class Car {
  
      @Id
      @GeneratedValue
      private long id;
  
      public long getId() {
          return id;
      }
  }
  </code></pre>
  
  <p>cars.xhtml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"&gt;
  &lt;head&gt;
      &lt;title&gt;test&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;/head&gt;
      &lt;body&gt;
          &lt;h:outputText value="I have #{carBean.carsCount}" /&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The complete stack trace error shown when I access the page:</p>
  
  <pre><code>javax.faces.FacesException: javax.ejb.EJBException: Injection failure; nested exception is: java.lang.IllegalStateException: EntityManagerFactory has not been created for PU : PuId=javaee6-0_0_1-SNAPSHOT_war#javaee6-0.0.1-SNAPSHOT.war#javaee6
      at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
      at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:258)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3751)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
      at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)
  Caused by: javax.ejb.EJBException: Injection failure; nested exception is: java.lang.IllegalStateException: EntityManagerFactory has not been created for PU : PuId=javaee6-0_0_1-SNAPSHOT_war#javaee6-0.0.1-SNAPSHOT.war#javaee6
  Caused by: java.lang.IllegalStateException: EntityManagerFactory has not been created for PU : PuId=javaee6-0_0_1-SNAPSHOT_war#javaee6-0.0.1-SNAPSHOT.war#javaee6
      at com.ibm.ws.jpa.management.JPAPUnitInfo.getEntityManagerFactory(JPAPUnitInfo.java:1425)
      at com.ibm.ws.jpa.management.JPAPUnitInfo.getEntityManagerPool(JPAPUnitInfo.java:1652)
      at com.ibm.ws.jpa.management.JPATxEntityManager.&lt;init&gt;(JPATxEntityManager.java:161)
      at com.ibm.ws.jpa.management.AbstractJPAComponent.getEntityManager(AbstractJPAComponent.java:509)
      at com.ibm.ws.jpa.management.JPAComponentImpl.getEntityManager(JPAComponentImpl.java:128)
      at com.ibm.ws.util.JPAJndiLookupObjectFactory.getObjectInstance(JPAJndiLookupObjectFactory.java:176)
      at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1038)
      at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectableObject(InjectionBinding.java:1003)
      at com.ibm.wsspi.injectionengine.InjectionTarget.inject(InjectionTarget.java:198)
      at com.ibm.ws.injectionengine.AbstractInjectionEngine.inject(AbstractInjectionEngine.java:924)
      at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:300)
      at com.ibm.ejs.container.BeanOFactory.create(BeanOFactory.java:147)
      at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1240)
      at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1358)
      at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:88)
      at com.ibm.ejs.container.activator.Activator.preInvokeActivateBean(Activator.java:614)
      at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:4110)
      at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3476)
      at com.learning.business.car.EJSLocalNSLCarRepo_a1ab5865.getAll(EJSLocalNSLCarRepo_a1ab5865.java)
      at com.learning.business.car.CarBean.getCarsCount(CarBean.java:13)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:611)
      at javax.el.BeanELResolver.getValue(BeanELResolver.java:91)
      at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
      at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
      at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
      at org.apache.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:44)
      at org.apache.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:50)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283)
      at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
      at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:243)
      at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
      at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:343)
      at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:295)
      at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderOutput(HtmlTextRendererBase.java:92)
      at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:79)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:535)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:626)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:622)
      at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1320)
      at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
      at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1032)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3751)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
      at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
      at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)
  </code></pre>