title: Liquibase + JPA: Run order
body: <p>I have a Java Project in which I use JPA for persistence.
  Now I want to integrate LiquiBase in my project, but I don't know how to change the order JPA/Liquibase are executed.</p>
  
  <p>For clarity:
  Until now my persistence.xml looks like this:</p>
  
  <pre><code>&lt;property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/&gt;
  &lt;property name="javax.persistence.jdbc.url" value=.../&gt;
  &lt;property name="javax.persistence.jdbc.user" value=.../&gt;
  &lt;property name="eclipselink.ddl-generation" value="create-or-extend-tables"/&gt;
  </code></pre>
  
  <p>I now tried to set:</p>
  
  <pre><code>&lt;property name="eclipselink.ddl-generation" value="none"/&gt;
  </code></pre>
  
  <p>so that liquibase handles all the database-stuff. </p>
  
  <p>But now when I run my Code, JPA throws an Error because some tables are missing, although these tables should be created by liquibase, which leads me to believe that JPA is running before liquibase.</p>
  
  <p>How do I change that order?
  Until now, Liquibase is executed in code via this lines:</p>
  
  <pre><code>java.sql.Connection connection = openConnection(); //your openConnection logic here
  
  Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
  
  Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database);
  
  liquibase.update(new Contexts(), new LabelExpression());
  </code></pre>
  
  <p>I read somewhere that this could be achieved via Liquibase Servlet listener, but that requires the database data-source, and I dont know how to get that.</p>
  
  <p>Liquibase itself works fine.</p>