2
Hello,
I need some help. I’m trying to make a transaction on Ibernate.
The problem is that by giving a close
, the data are modified in the database, but this occurs WARN
:
WARN [Commonannotationbeanpostprocessor] Invocation of Destroy method failed on bean with name 'sessionCreator': org.hibernate.Sessionexception: Session was already closed
The code I’m using is this:
Transaction transacao = null;
try {
transacao = session.beginTransaction();
contaDao.atualiza(conta);
transacao.commit();
session.close();
} catch (Exception err) {
if (transacao != null) {
transacao.rollback();
}
}
How can I solve this problem?
Follows the whole method:
public void atualizarSaldo(LancamentoDados dados, double novoSaldo) {
ContaBancaria conta = new ContaBancaria();
HistoricoConta historicoSaldoConta = new HistoricoConta(this.historicoConta);
conta.setCodContaBancaria(dados.getConta().getCodContaBancaria());
conta.setNumeroContaBancaria(dados.getConta().getNumeroContaBancaria());
conta.setSaldoContaBancaria(novoSaldo);
conta.setAnotacaoContaBancaria("Sem conta");
Transaction transacao = null;
try {
transacao = session.beginTransaction();
System.out.println("Estou no try em atualiza");
contaDao.atualiza(conta);
historicoSaldoConta.inserirSaldoConta(conta);
transacao.commit();
} catch (Exception err) {
System.out.println("Erro meu : " + err);
if (transacao != null) {
transacao.rollback();
}
}
}
you take your Session so Session Session = sessionFactory.openSession();?
– Rafael
Rafael, I’m not wearing it like this
– Ivan Alves
@Ivanalves Can you put your entire method? You’re opening the session somewhere?
– DiegoAugusto
@Diegoaugusto put the whole method
– Ivan Alves
@Ivanalves Where you are opening the session?
– DiegoAugusto