Christian Tu created OPENJPA-2848:
-------------------------------------

             Summary: Duplicate DROP SEQUENCE statements generated by 
MappingTool/SchemaTool
                 Key: OPENJPA-2848
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2848
             Project: OpenJPA
          Issue Type: Bug
          Components: jdbc
    Affects Versions: 3.1.2
            Reporter: Christian Tu
         Attachments: openjpa-mappingtool-test.zip

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:
{code:java}
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]);
                     }
                 }
{code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to