openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Dazey (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (OPENJPA-2721) Table drops can use wrong default schema
Date Thu, 19 Oct 2017 21:33:01 GMT

     [ 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:
<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
{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, Derby

  was:
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
{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}

Derby
{code:java}
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Schema 'derbyAdmin' does not
exist {stmnt 1467091305 
DROP TABLE SIMPLE_ENTITY } [code=30000, state=42Y07]
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:219)
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:203)
{code}

SQLServer
{code:java}
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Cannot drop the table 'SIMPLE_ENTITY',
because it does not exist or you do not have permission. {stmnt -886180135 
DROP TABLE SIMPLE_ENTITY } [code=3701, state=S0005]
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:219)
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:203)
{code:java}

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


> 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:
> <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
> {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,
Derby



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message