I cannot delete data from an entity

Asked

Viewed 44 times

0

I have a method that deletes a company entity and its attachments, after the archiving of a protocol, however, when I try to delete, this happens:

Caused by: java.sql.BatchUpdateException: Entrada em lote 0 delete from pessoa where codigo='34635PI' foi abortada. Chame getNextException para ver a causa.

Method to delete the company and its attached files

public static void excluirEmpresaAposArquivamentoProtocolo(ArquivoRegistroOnlineEmpresaDao arquivoRegistroOnlineEmpresaDao, EmpresaDao empresaDao, String codigoEmpresa) {
    Empresa empresa = empresaDao.pesquisarPorId(codigoEmpresa);
    Map<String, Object> params = new HashMap<String, Object>();
    String queryArquivosRegistro = "SELECT aroe FROM ArquivoRegistroOnlineEmpresa aroe "
            + "WHERE aroe.empresa = :empresa";
    params.put("empresa", empresa);

    List<ArquivoRegistroOnlineEmpresa> arquivosRegistroOnlineEmpresa = arquivoRegistroOnlineEmpresaDao.listPesqParam(queryArquivosRegistro, params);

    for(ArquivoRegistroOnlineEmpresa aroe : arquivosRegistroOnlineEmpresa) {
        File f = new File(aroe.getCaminhoArquivo());
        f.delete();
        arquivoRegistroOnlineEmpresaDao.excluir(aroe);
    }

    empresaDao.excluir(empresa);
}

Stacktrace

Link to the Stacktrace

  • Userj, please edit post the error stacktrace.

  • I put in the Pastebin, the link is in the question

  • I can’t access this link, so there’s no way to help it.

  • Read on: https://answall.com/help/how-to-ask

  • I chose to put in Pastebin, because of character limitation

1 answer

2


Based on the stack trace error it seems to me that at some point you are trying to delete a pessoa and she is still referenced by a protocolo.

Watch the next row of your stack trace:

Grave: 143318 [http-thread-pool-8080(4)] ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: update or delete on table "pessoa" violates foreign key constraint "fk53b964b79c58666b" on table "protocolo"
  Detalhe: Key (codigo)=(0000034635TPPI) is still referenced from table "protocolo".

Basically there is a key Foreign of the table protocolo to the table pessoa and therefore you cannot exclude the pessoa.

If your goal is to actually delete the pessoa I suggest you remove the entity first protocolo.

  • That’s right, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.