DdlUtils
  1. DdlUtils
  2. DDLUTILS-159

primary key column change causes exception

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0 RC1
    • Labels:
      None
    • Environment:
      Windows, SapDB 7.4 and Oracle 8

      Description

      I have the folowing table definition:

      <?xml version="1.0"?>
      <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
      <database name="rmdb">
      <table name="ADDRESS">
      <column name="ID" primaryKey="true" required="true" type="INTEGER"/>
      <column name="TOWN" primaryKey="false" required="false" type="VARCHAR" size="40"/>
      </table>
      </database>

      I want to change the name of the primary key column. The new schema definition is:

      <?xml version="1.0"?>
      <!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
      <database name="rmdb">
      <table name="ADDRESS">
      <column name="ADDRESSID" primaryKey="true" required="true" type="INTEGER"/>
      <column name="TOWN" primaryKey="false" required="false" type="VARCHAR" size="40"/>
      </table>
      </database>

      DdlUtils throws the following exception in the alter table process:

      Exception in thread "main" java.lang.NullPointerException
      at org.apache.ddlutils.alteration.AddPrimaryKeyChange.apply(AddPrimaryKeyChange.java:69)
      at org.apache.ddlutils.platform.SqlBuilder.processChange(SqlBuilder.java:1160)
      at org.apache.ddlutils.platform.sapdb.SapDbBuilder.processTableStructureChanges(SapDbBuilder.java:180)
      at org.apache.ddlutils.platform.SqlBuilder.processTableStructureChanges(SqlBuilder.java:921)
      at org.apache.ddlutils.platform.SqlBuilder.processTableStructureChanges(SqlBuilder.java:797)
      at org.apache.ddlutils.platform.SqlBuilder.processChanges(SqlBuilder.java:576)
      at org.apache.ddlutils.platform.SqlBuilder.alterDatabase(SqlBuilder.java:469)
      at org.apache.ddlutils.platform.PlatformImplBase.getAlterTablesSql(PlatformImplBase.java:756)

      The reason is, that an alteration of the table name is not supported via 'alter table' so DdlUtils recreates the table. But in 'SapDbBuilder.processTableStructureChanges' the new primary key is created before the table is recreated in the super-Method. So 'AddPrimaryKeyChange refers to a column that is not present and throws an exception.

      The behaviour is the same with Oracle:

      Exception in thread "main" java.lang.NullPointerException
      at org.apache.ddlutils.alteration.AddPrimaryKeyChange.apply(AddPrimaryKeyChange.java:69)
      at org.apache.ddlutils.platform.SqlBuilder.processChange(SqlBuilder.java:1160)
      at org.apache.ddlutils.platform.oracle.Oracle8Builder.processTableStructureChanges(Oracle8Builder.java:488)
      at org.apache.ddlutils.platform.SqlBuilder.processTableStructureChanges(SqlBuilder.java:921)
      at org.apache.ddlutils.platform.SqlBuilder.processTableStructureChanges(SqlBuilder.java:797)
      at org.apache.ddlutils.platform.SqlBuilder.processChanges(SqlBuilder.java:576)
      at org.apache.ddlutils.platform.SqlBuilder.alterDatabase(SqlBuilder.java:469)
      at org.apache.ddlutils.platform.PlatformImplBase.getAlterTablesSql(PlatformImplBase.java:756)

        Issue Links

          Activity

            People

            • Assignee:
              Thomas Dudziak
              Reporter:
              Stefan Huber
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development