OPENJPA-2614 run ALTER SEQUENCE in a separate tx

Quite a lot databases force a commit on DDL changes.
For sequences we try to run an ALTER SEQUENCE to make the sequence
reflect the allocationSize. Doing this will commit all outstanding open
DB changes in Oracle and a few other databases.
We now open a new connection.
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java
index ef364a4..98de566 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractJDBCSeq.java
@@ -149,6 +149,14 @@
         return (JDBCStore) ctx.getStoreManager().getInnermostDelegate();
     }
 
+
+    /**
+     * @see #getConnection(JDBCStore, boolean) but without forcing a connection.
+     */
+    protected Connection getConnection(JDBCStore store) throws SQLException {
+        return getConnection(store, false);
+    }
+
     /**
      * <P>Return the connection to use based on the type of sequence. This
      * connection will automatically be closed; do not close it.</P>
@@ -160,10 +168,11 @@
      * <P>Otherwise a new connection will be obtained using DataSource2 from the
      * current configuration. In this case autocommit is set to false prior to
      * returning the connection.</P>
+     * @param forceNewConnection if {@code true} a new connection will be forced
      */
-    protected Connection getConnection(JDBCStore store)
+    protected Connection getConnection(JDBCStore store, boolean forceNewConnection)
         throws SQLException {
-        if (type == TYPE_TRANSACTIONAL || type == TYPE_CONTIGUOUS) {
+        if (!forceNewConnection && (type == TYPE_TRANSACTIONAL || type == TYPE_CONTIGUOUS)) {
             // Also increments ref count.
             return store.getConnection();
         }
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
index 8369b4a..d15852d 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
@@ -227,15 +227,21 @@
                     // If this fails, we will warn the user at most one time and set _allocated and _increment to 1 so
                     // as to not potentially insert records ahead of what the database thinks is the next sequence
                     // value.
-                    if (updateSql(conn, dict.getAlterSequenceSQL(_seq)) == -1) {
-                        if (!alreadyLoggedAlterSeqFailure) {
-                            Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
-                            if (log.isWarnEnabled()) {
-                                log.warn(_loc.get("fallback-no-seq-cache", _seqName));
+
+                    // first we have to allocate a new connection as some databases do an implicit commit
+                    // if a DDL gets changed. Others do blow up on a DDL change
+                    try (Connection newConn = getConnection(store, true)) {
+                        if (updateSql(newConn, dict.getAlterSequenceSQL(_seq)) == -1) {
+                            newConn.commit(); // new connection has autoCommit=false
+                            if (!alreadyLoggedAlterSeqFailure) {
+                                Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+                                if (log.isWarnEnabled()) {
+                                    log.warn(_loc.get("fallback-no-seq-cache", _seqName));
+                                }
                             }
+                            alreadyLoggedAlterSeqFailure = true;
+                            _allocate = 1;
                         }
-                        alreadyLoggedAlterSeqFailure = true;
-                        _allocate = 1;
                     }
                 } else {
                     if (!alreadyLoggedAlterSeqDisabled) {