title: how to set up a h2 in memory database with hibernate jpa?
body: <p>Trying to set up an in memory h2 database.</p>
  
  <p>The persistence.xml is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--
    ~ Hibernate, Relational Persistence for Idiomatic Java
    ~
    ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
    ~ See the lgpl.txt file in the root directory or &lt;http://www.gnu.org/licenses/lgpl-2.1.html&gt;.
    --&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      version="1.0"&gt;
  
      &lt;persistence-unit name="HelloWorldPU" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;jdbc:h2:mem:test&lt;/jta-data-source&gt;
          &lt;class&gt;helloworld.Message&lt;/class&gt;
          &lt;properties&gt;
          &lt;property name="javax.persistence.schema-generation.database.action" value="drop-and-create"&gt;&lt;/property&gt;
              &lt;property name="hibernate.connection.driver_class" value="org.h2.Driver"/&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create-drop"/&gt;
              &lt;property name="hibernate.archive.autodetection" value="class"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The class i run is:</p>
  
  <pre><code>package learnHibernate;
  
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  public class HelloWorldJPA {
   public static void main(String[] args) {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("HelloWorldPU");
      System.out.println(emf);
  }
  }
  </code></pre>
  
  <p>I am getting an error:</p>
  
  <blockquote>
    <p>Caused by: org.hibernate.engine.jndi.JndiException: Error parsing JNDI name [jdbc:h2:mem:test]
        at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:124)
        at org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:95)
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:98)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
        at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
        ... 14 more
    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
        at javax.naming.InitialContext.getNameParser(InitialContext.java:505)
        at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:118)
        ... 24 more</p>
  </blockquote>
  
  <p>What could be the reason?</p>
  
  <p>How can i fix this.</p>