[ 
https://issues.apache.org/jira/browse/OPENJPA-1698?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12888899#action_12888899
 ] 

Oliver Bayer commented on OPENJPA-1698:
---------------------------------------

Hi Rick,

thanks for answering. You're right about the not working "IF EXISTS" in 
postgres. I didn't thought about it when I posted my suggested bugfix.
Here is the error log (I hope I removed all jsf follow-up errors from my jsf 
test app):

<openjpa-2.0.0-r422266:935683 nonfatal general error> 
org.apache.openjpa.persistence.PersistenceException: ERROR: Relation 
»openjpa_sequence_table« doesn't exist
  Position: 13 {stmnt 8577594 DELETE FROM OPENJPA_SEQUENCE_TABLE} [code=0, 
state=42P01]
        at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:556)
        at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:456)
        at 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:155)
        at 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:159)
        at 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:117)
        at 
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:199)
        at 
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
        at 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:213)
        at 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:151)
        at 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:57)
... 27 more

at 
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:257)
        at 
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:241)
        at 
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:70)
        at 
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingStatement.executeUpdate(LoggingConnectionDecorator.java:951)
        at 
org.apache.openjpa.lib.jdbc.DelegatingStatement.executeUpdate(DelegatingStatement.java:136)
        at 
org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1200)
        at 
org.apache.openjpa.jdbc.schema.SchemaTool.deleteTableContents(SchemaTool.java:431)
        at org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:339)
        at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:504)
        ... 45 more

The error message "ERROR: Relation »openjpa_sequence_table« doesn't exist" 
comes directly from postgres. I get the same one if I try to execute the delete 
statement (shown above) inside the postgres sql editor.

HTH Oli

> SchemaAction=deleteTableContents throws error if table doesn't exist
> --------------------------------------------------------------------
>
>                 Key: OPENJPA-1698
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1698
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 2.0.0
>         Environment: Win XP, Postgres 8.4, OpenJPA 2.0.0
>            Reporter: Oliver Bayer
>
> Hi,
> I want to set up my project during development so that all table contents are 
> deleted with the following property in persistence.xml:
> <property name="openjpa.jdbc.SynchronizeMappings" 
> value="buildSchema(SchemaAction=add,SchemaAction=deleteTableContents)"/>
> If I start up with an empty database I get the following error:
> org.apache.openjpa.persistence.PersistenceException: ERROR: Relation 
> >>openjpa_sequence_table<< doesn't exist.
> This error is raised because of the following sql statement: DELETE FROM 
> OPENJPA_SEQUENCE_TABLE.
> My suggested solution would be to modify 
> DBDictionary.getDeleteTableContentsSQL so that it only deletes content from a 
> table if the table exists.
> DBDictionary: Line 2183
> ---------------------------------
> change: deleteSQL.add("DELETE FROM " + 
> toDBName(tables[i].getFullIdentifier()));
> to: deleteSQL.add("DELETE FROM " + toDBName(tables[i].getFullIdentifier()) + 
> " IF EXISTS");
> What do you mean: Is this a valid bugfix? I'm looking forward to your 
> responses.
> Greets Oli

-- 
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