Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

JDBC batch delete statement.executeBatch() throw read-only transaction exception

$
0
0

I use batch delete via JDBC statement batch update using Postgresql driver.

It throws org.postgresql.util.PSQLException: ERROR: cannot execute DELETE in a read-only transaction

String childTableDelete = "delete from child c using parent p where p.id=c.p_id and p.expired=true";String parentTableDelete = "delete from parent where expired=true";try (final Connection connection = this.dataSource.getConnection();                final Statement statement = connection.createStatement())        {            connection.setAutoCommit(false);            statement.addBatch(childTableDelete);            statement.addBatch(parentTableDelete);            try            {                final int count[] = statement.executeBatch();                connection.commit();                             }            catch (final BatchUpdateException batchUpdateException)            {                connection.rollback();                          }        }        catch (final SQLException exception)        {            eexception.printStackTrace();        }

I am expecting all Childs records to be deleted that are associated with parent and then the parent records.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>