[
https://issues.apache.org/jira/browse/OPENJPA-2848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17310290#comment-17310290
]
ASF subversion and git services commented on OPENJPA-2848:
----------------------------------------------------------
Commit c7c13d3e8be25512b0e9451f5bbe3706a07c7206 in openjpa's branch
refs/heads/master from Mark Struberg
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=c7c13d3 ]
OPENJPA-2848 duplicate DROP SEQUENCE stmt
txs to Christian Tu for the patch!
> 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
> Assignee: Mark Struberg
> Priority: Minor
> 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)