0
I have on a screen a process table and want to delete one of them. This is a piece of mine 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 method exclude(Procedure):
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 method remove(T object) in Genericdao
public void remover(T objeto) {
Object o = manager.merge(objeto);
manager.remove(o);
}
When I click on 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?
Select the object after use
remove
. Don’t forget to open and close a transaction.– Marcelo Gomes
I don’t know if I understood how to select an object, take a look at line 44 and 45 of that code to see if I did it right. As to open and close the transaction this is being done by a third party with CDI.
– Jamilson Junior
It would look something like this: Object o = manager.find(Object.class, id)
. Eu uso CDI e no DAO eu uso a annotation
@Transactional`.– Marcelo Gomes
I tried that, but it still doesn’t work. That one is the new method I created.
– Jamilson Junior
Put a method that exists and works so that we can compare. In this case if you pass the object as parameter, I believe it is not necessary
manager.merge
. Could use the methodremove
' directly. I use the "Weld" implementation and created a class to assist transactions and use the annotation@Transaction
in each method that updates or removes objects from the BD.– Marcelo Gomes
Since you are making a change on a bank line it is necessary to open the transaction and after the change commit the change. Where do you do it?
– luanlucas
It may not have much to do.. But it’s worth trying: instead of doing
Object o
try to doT o
.– igventurelli
@Marcelogomes I still don’t understand very well how the CDI works, but I had a class in my project called
Transacional
. I put the note@Transacional
in my methodremover(Class<T> classe, Long id)
and now I can finally delete objects.– Jamilson Junior
I will add this answer and you mark as the correct answer. Who good it worked.
– Marcelo Gomes