title: Generating Tables from entities - JPA
body: <p>I want to gernerate a table in a Database.
  I use a non-embedded Derbry Database and glassfish4.0 + ecipse link.</p>
  
  <p>First I configured a new JDBC connectionpool with the glassfish admin-console.
  The URL ist <code>jdbc:derby://localhost:1527/firstEeDb;create=true</code> (Derby networkserver ist Stated).</p>
  
  <p>Then i created a new JDBC Resource named testDb and after the first Acces to the DB over Eclipse Database-view there is a folder named testDb in my derby folder.</p>
  
  <p>I tried <code>right-click -&gt; JPA Tools -&gt; Generate Tables from Entities</code>, but it doesn't work.</p>
  
  <p><strong>I get this exception:</strong></p>
  
  <pre><code>[EL Config]: metadata: The column name for element [id] is being defaulted to: ID.
  [EL Config]: metadata: The column name for element [strasse] is being defaulted to: STRASSE.
  [EL Config]: metadata: The column name for element [plz] is being defaulted to: PLZ.
  [EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
  Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
  Exception Description: Cannot acquire data source [jdbc/testDb].
  Internal Exception: 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 org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:762)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
      at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.generate(Main.java:90)
      at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:81)
      at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)
  Caused by: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
  Exception Description: Cannot acquire data source [jdbc/testDb].
  Internal Exception: 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 org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:520)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
      at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:203)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:734)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
      at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:681)
      ... 7 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:307)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:404)
      at javax.naming.InitialContext.lookup(InitialContext.java:415)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
      ... 12 more
  [EL Severe]: ejb: Local Exception Stack: 
  Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
  Exception Description: Cannot acquire data source [jdbc/testDb].
  Internal Exception: 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 org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:520)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
      at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:203)
      at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:734)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
      at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:681)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
      at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
      at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.generate(Main.java:90)
      at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:81)
      at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)
  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:307)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:404)
      at javax.naming.InitialContext.lookup(InitialContext.java:415)
      at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
      ... 12 more
  </code></pre>
  
  <p><strong>Entity:</strong></p>
  
  <pre><code>import java.io.Serializable;
  
  import javax.inject.Named;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  @Entity
  @Named
  public class Adresse implements Serializable {
  
      private static final long serialVersionUID = -1864720487909609602L;
  
      @Id
      @GeneratedValue
      private long id;
  
      private int plz;    
      private String strasse; 
  
      public Adresse() {
      }
  
      public Adresse(int plz, String strasse) {
          super();
          this.plz = plz;
          this.strasse = strasse;
      }
  
      public int getPlz() {
          return plz;
      }
  
      public void setPlz(int plz) {
          this.plz = plz;
      }
  
      public String getStrasse() {
          return strasse;
      }
  
      public void setStrasse(String strasse) {
          this.strasse = strasse;
      }
  }
  </code></pre>
  
  <p><strong>persistece.xml</strong></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="Adressbuch" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;jdbc/testDb&lt;/jta-data-source&gt;
          &lt;class&gt;myPackage.Adresse&lt;/class&gt;
  
          &lt;properties&gt;
              &lt;!-- EclipseLink should create the database schema automatically --&gt;
              &lt;property name="eclipselink.ddl-generation" value="create-tables" /&gt;
              &lt;property name="eclipselink.ddl-generation.output-mode"
                  value="database" /&gt;
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt; 
  </code></pre>