primary key column change causes exception
------------------------------------------

                 Key: DDLUTILS-159
                 URL: https://issues.apache.org/jira/browse/DDLUTILS-159
             Project: DdlUtils
          Issue Type: Bug
          Components: Core (No specific database)
         Environment: Windows, SapDB 7.4 and Oracle 8
            Reporter: Stefan Huber
         Assigned To: Thomas Dudziak


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)


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to