title: Automatically creating and/or extending JPA tables with Wildfly, EclipseLink and Postgres
body: <p>I have experienced a strange matter with a Java EE application running on Wildfly 8.1.0 as the server and Postgres as our database system in combination with EclipseLink as the persistence provider <em>(the reasons why I want to study the costs of migrating from built-in Hibernate to EclipseLink don't matter here)</em>. </p>
  
  <p>I was getting used to the Hibernate feature of automatically extending the existing database tables by newly added columns when extending the corresponding Entity classes and it would be charming if EclipseLink was able to do so, too - studying the documentation, EclipseLink provides the property</p>
  
  <pre><code>&lt;property name="eclipselink.ddl-generation" value="create-or-extend-tables"/&gt;
  </code></pre>
  
  <p>which sound good to me, but a short test lead to the disillusioning result that it does not work "out of the box" (see minimal example below). Interestingly, if I simply create the respective table in the database without any columns, the table gets filled and works as I wanted, but neither <code>create-or-extend-tables</code> nor <code>drop-and-create-tables</code> and even not <code>create-tables</code> works - the first two only, if I add the mentioned empty table.</p>
  
  <p>Has anyone encountered a situation like this and possibly found a solution?</p>
  
  <p>Additionally, I learned about a Postgres problem regarding transactions </p>
  
  <blockquote>
    <p>PostgreSQL seems to abort the transaction if an error occurs, so accessing the database after a failure may not be possible until after calling rollback. (<a href="https://wiki.eclipse.org/EclipseLink/FAQ/JPA/PostgreSQL" rel="nofollow">EclipseLink/FAQ/JPA/PostgreSQL</a>)</p>
  </blockquote>
  
  <p>and as certain error logs point to problems with transactions, maybe this could be a part of the problem?</p>
  
  <h2>Minimal Example</h2>
  
  <p><strong><code>persistence.xml</code></strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1"&gt;
  
      &lt;persistence-unit name="..." transaction-type="JTA"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;java:jboss/datasources/PostgresDS&lt;/jta-data-source&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;shared-cache-mode&gt;ENABLE_SELECTIVE&lt;/shared-cache-mode&gt;
          &lt;properties&gt;
              &lt;property name="eclipselink.ddl-generation" value="create-tables"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong><code>Name.java</code></strong></p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  public class Name {
  
      private String id;
  
      private String name;
  
      @Id
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>