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.