Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2848

Duplicate DROP SEQUENCE statements generated by MappingTool/SchemaTool

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.1.2
    • None
    • jdbc
    • None
    • Patch Available

    Description

      Using the MappingTool with the action dropSchema to generate DDL statements from Java classes, results in duplicate DROP SEQUENCE statements, if a SEQUENCE of the same name already exists in the database.

      I have added a small Maven example that demonstrates this. It uses the openjpa-maven-plugin with the sql goal and build/dropSchema action on a Friend class. The sql generated from the build action is used to initialize an h2 db with a sequence. The subsequent dropSchema action then creates a file target/drop.sql where the duplicate DROP SEQUENCE statement can be observed.

      Using Version 2.4.3 of openjpa-maven-plugin results in a single DROP SEQUENCE statement.

      Not initializing the database with the sequence first, also results in a single DROP SEQUENCE statement.

       

      I'm not familiar with OpenJPA an its code base. But it seems reasonable to me that the offending code is in SchemaTool, where this if should be an else if to prevent dropSequence from being called twice:

      diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
      index 1bdbf6416..32a803ce5 100644
      --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
      +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
      @@ -918,9 +918,7 @@ public class SchemaTool {
                                   dbSeq.getSchema().removeSequence(dbSeq);
                               else
                                   _log.warn(_loc.get("drop-seq", seqs[j]));
      -                    }
      -
      -                    if (_writer != null) {
      +                    } else if (_writer != null) {
                               dropSequence(seqs[j]);
                           }
                       }
      

       

      Attachments

        1. openjpa-mappingtool-test.zip
          3 kB
          Christian Tu

        Activity

          People

            struberg Mark Struberg
            honboubao Christian Tu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: