Why can not I delete an object with Hibernate?

0

I have on a screen a process table and I want to delete one of them. This is a piece of my datatable :

<p:column headerText="Excluir" style="width:68px">
    <p:commandButton actionListener="#{processoMB.excluir(obj)}"
        icon="ui-icon-trash" title="Excluir" styleClass="btn btn-block"
        update=":frmTabela :dlgInformacao" alt="Excluir">
        <p:confirm header="Confirmação" message="Deseja excluir?" />
    </p:commandButton>
</p:column>

This is my delete method (Process Process) :

public void excluir(Processo processo) {
    try {
        daoProcesso.remover(processo);
        ExibirMensagem.exibirMensagem(Mensagem.SUCESSO);
        operacoesDeAlteracao();
    } catch (Exception e) {
        ExibirMensagem.exibirMensagem(Mensagem.ERRO);
        e.printStackTrace();
    }
}

And this is my remove (Object T) method in GenericDAO

public void remover(T objeto) {
    Object  o = manager.merge(objeto);
    manager.remove(o);
}

When I click the button to delete a process Hibernate does only these operations and does not delete my process object:

Hibernate: select processo0_.id_processo as id_proce1_0_0_, processo0_.descricao as descrica2_0_0_ from tab_processo processo0_ where processo0_.id_processo=?
Hibernate: select processo0_.id_processo as id_proce1_0_, processo0_.descricao as descrica2_0_ from tab_processo processo0_ where id_processo<>0

What am I doing wrong?

    
asked by anonymous 02.01.2018 / 21:34

2 answers

0

Using CDI you should note the method in DAO or Service, depending on your strategy:

@Transacional 
public void excluir(Processo processo) {
    try {
        daoProcesso.remover(processo);
        ExibirMensagem.exibirMensagem(Mensagem.SUCESSO);
        operacoesDeAlteracao();
    } catch (Exception e) {
        ExibirMensagem.exibirMensagem(Mensagem.ERRO);
        e.printStackTrace();
    }
}
    
09.01.2018 / 19:40
0
   try {

           public void remover(T objeto) {
            manager.getTransaction().begin() ;
            Object  o = manager.merge(objeto);
            manager.remove(o);
            manager.getTransaction().commit();
         }

 } catch (Exception ex) {
    ex.printStackTrace();                          
    manager.getTransaction().rollback();                         
 }

You can try another option!

manager.remove( manager.find(seuObjeto.class, id) );

If the other option does not work try yes! if you have a method that looks for id you can use it to replace the manager.find ().     

03.01.2018 / 18:47