java.lang.Illegalargumentexception: Attempt to create delete Event with null Entity

Asked

Viewed 237 times

0

I have a simple Manufacturer model class only with the attribute 'Description'. My database is populated and the save and edit method is working normally. However when I delete generates in the console the following error:

java.lang.IllegalArgumentException: attempt to create delete event with null entity
at org.hibernate.event.spi.DeleteEvent.<init>(DeleteEvent.java:48)
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:896)
at br.com.drogaria.dao.GenericDAO.excluir(GenericDAO.java:48)
at br.com.drogaria.bean.FabricanteBean.excluir(FabricanteBean.java:62)

Genericdao

public void excluir(Entidade entidade) {
    Session sessao = HibernateUtil.getFabricaDeSessoes().openSession();
    Transaction transacao = null;

    try {
        transacao = sessao.beginTransaction();
        sessao.delete(entidade);
        transacao.commit();
    } catch (RuntimeException erro) {
        if (transacao != null) {
            transacao.rollback();
        }
        throw erro;
    } finally {
        sessao.close();
    }
}

Bean class, but business logic in the future I will put in a Service class:

public void excluir(ActionEvent evento) {
    try {
        this.fabricante = (Fabricante) evento.getComponent().getAttributes().get("fabricanteSelecionado");

        FabricanteDAO fabricanteDAO = new FabricanteDAO();
        //this.fabricante = fabricanteDAO.buscar(fabricante.getCodigo());

        fabricanteDAO.excluir(fabricante);
        this.fabricantes = fabricanteDAO.listar();

        Messages.addGlobalInfo("Fabricante excluído com sucesso!");
    } catch (RuntimeException erro) {
        Messages.addGlobalError("Ocorreu um erro ao tentar excluir um Fabricante.");
        erro.printStackTrace();
    }

xhtml

<p:commandButton icon="ui-icon-trash" actionListener="#{fabricanteBean.excluir}"
            update=":mensagem :formListagem:tabela" title="Excluir">
    <p:confirm header="Confirmação" message="Deseja excluir o Fabricante?"
        icon="ui-icon-alert">
        <f:attribute name="fabricanteSelecionado" value="#{fabricante}" />
    </p:confirm>

1 answer

0


In fact the classes are correct, checking later calmly I realized that the error was in the xhtml in the confirmDialog, I put f:attribute inside the p:confirm, wrong: And the correct is as below.

<p:commandButton icon="ui-icon-trash" actionListener="#{fabricanteBean.excluir}"
        update=":mensagem :formListagem:tabela" title="Excluir">
    <p:confirm header="Confirmação" message="Deseja excluir o Fabricante #{fabricante.descricao}?" 
            icon="ui-icon-alert" />
        <f:attribute name="fabricanteSelecionado" value="#{fabricante}" />
</p:commandButton>

Browser other questions tagged

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