[ https://issues.apache.org/jira/browse/OPENJPA-2721?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Will Dazey updated OPENJPA-2721: -------------------------------- 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: 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 (on DB2): {code:java} 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) {code} 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, MySQL, was: It looks like OpenJPA will drop tables from the wrong schemas if the default schema is not set by the persistence property or the orm.xml mapping. For example: DB Tables: unknown_schema.SIMPLE_ENTITY Properties: If the default schema is not set as described above and your DS is connected using dbadmin. OpenJPA will find the table SIMPLE_ENTITY in the schema "unknown_schema", but will then throw the following exception (on DB2): {code:java} 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) {code} 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, MySQL, > Table drops can use wrong default schema > ---------------------------------------- > > Key: OPENJPA-2721 > URL: https://issues.apache.org/jira/browse/OPENJPA-2721 > Project: OpenJPA > Issue Type: Bug > Components: jpa > Affects Versions: 2.2.2 > Reporter: Will Dazey > Assignee: Will Dazey > Priority: Minor > > 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: > > 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 (on DB2): > {code:java} > 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) > {code} > 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, MySQL, -- This message was sent by Atlassian JIRA (v6.4.14#64029)