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

Table drops can use wrong default schema

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.2.2
    • None
    • jpa
    • None

    Description

      It looks like OpenJPA will attempt to drop tables from the wrong schemas if the default schema is not set by the persistence property or the orm.xml mapping.

      For example, assume a database has a schema 'unknown_schema' with a table 'SIMPLE_ENTITY'

      Persistence properties:
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true,schemaAction='drop,add')"/>

      If the default schema is not set as described above and your DS is connected using user 'dbadmin'. OpenJPA will find the table 'SIMPLE_ENTITY' in the schema "unknown_schema". This will lead OpenJPA to think it's ok to drop table 'SIMPLE_ENTITY' because it was found earlier (even though it was in a schema unaffiliated with this persistence context) and OpenJPA will then throw the following exception:

      DB2

      Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DBADMIN.SIMPLE_ENTITY, DRIVER=4.8.87 {stmnt 414359678 
      DROP TABLE SIMPLE_ENTITY } [code=-204, state=42704]
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:219)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:203)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:59)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingStatement.executeUpdate(LoggingConnectionDecorator.java:914)
      	at org.apache.openjpa.lib.jdbc.DelegatingStatement.executeUpdate(DelegatingStatement.java:118)
      	at org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1224)
      	at org.apache.openjpa.jdbc.schema.SchemaTool.dropTable(SchemaTool.java:985)
      	at org.apache.openjpa.jdbc.schema.SchemaTool.dropTables(SchemaTool.java:959)
      	at org.apache.openjpa.jdbc.schema.SchemaTool.drop(SchemaTool.java:872)
      	at org.apache.openjpa.jdbc.schema.SchemaTool.drop(SchemaTool.java:375)
      	at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:345)
      

      The issue is that OpenJPA does not use the correct schema when scanning for tables to drop. This should be an issue on all platforms, but I was only able to test on DB2, Oracle, Derby

      Attachments

        1. OPENJPA-2721-2.2.x.patch
          15 kB
          Will Dazey

        Activity

          People

            dazeydev Will Dazey
            dazeydev Will Dazey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: