title: Tables not getting auto-created in Apache Derby when using EJB3/Hibernate
body: <p>I have an EJB3 entity bean Player which is annotated as given below:</p>
  
  <pre><code>@Entity
  @Table(name = "PLAYER")
  public class Player {
      public Player() {
          super();
      }
  
      @Id
      @GeneratedValue
      private String id;
  
      @Column(nullable = false)
      private String firstName;
  
      private String lastName;
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  }
  </code></pre>
  
  <p>I am using Apache Derby DB to persist this. I have a <strong>persistence.xml</strong> file which explains the hibernate properties and I have define <code>hibernate.hbm2ddl.auto=create</code>. </p>
  
  <pre><code>&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="PlayerApp" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;class&gt;com.cricinfo.domain.Player&lt;/class&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.ClientDriver" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/&gt;  
          &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt;
          &lt;property name="hibernate.connection.url"
              value="jdbc:derby://localhost:1527/PlayerAppDB;create=true" /&gt;
          &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;property name="hibernate.format_sql" value="true" /&gt;           
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>But when I try to persist this object I get an exception saying </p>
  
  <pre><code>Caused by: org.apache.derby.client.am.SqlException: Table/View 'PLAYER' does not exist.
  at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
  </code></pre>
  
  <p>Isn't it supposed to auto create the tables since I have set the property <strong>hibernate.hbm2ddl.auto</strong> ? Or is there something that I am missing?</p>
  
  <p>My main method is as shown below:</p>
  
  <pre><code>public static void main(String[] args) {
  
      Player p = new Player();
      p.setFirstName("A");
      p.setLastName("BC");
  
      EntityManagerFactory factory = Persistence.createEntityManagerFactory("PlayerApp");
      EntityManager entityMgr =  factory.createEntityManager();
      EntityTransaction tx = entityMgr.getTransaction();
      tx.begin();
      entityMgr.persist(p);
      tx.commit();
      entityMgr.close();
      factory.close();
  }
  </code></pre>