Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

356
Visualizações
What is the replacement for Hibernate's Transaction.wasCommitted method?

I'm trying to update some code from an old version of Hibernate (version 3). It uses two methods of the Transaction interface that no longer exist in Hibernate 5.

session.getTransaction().wasCommitted()
session.getTransaction().wasRolledBack()

What is the equivalent in Hibernate 5?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You seem to be looking for session.getTransaction().getStatus(). For example,

session.getTransaction().getStatus() == TransactionStatus.COMMITTED
session.getTransaction().getStatus() == TransactionStatus.ROLLED_BACK

You may also want to examine the docs of TransactionStatus to see the relatively fine granularity of transaction statuses, as you might either want or need more inclusive substitutes than those above. Also, don't overlook TransactionStatus's methods, which you may find helpful. For example,

session.getTransaction().getStatus().isOneOf(
        TransactionStatus.MARKED_ROLLBACK,
        TransactionStatus.ROLLING_BACK,
        TransactionStatus.ROLLED_BACK)
over 4 years ago · Santiago Trujillo Relatório

0

I came across this issue when upgrading hibernate. This is how I modified my code

Transaction trans = null;

Once we commit the transaction we can check its status and return Boolean value as true or false as

  boolean wasCommitted=trans.getStatus().equals("ACTIVE")?true:false;

We might get confused between Active and COMMITTED but I found that active in hibernate is eqivalent to wasCommitted() in previous version

ACTIVE,
    /**
     * The transaction has been completed successfully.
     */
    COMMITTED,
    /**
     * The transaction has been rolled back.
     */
    ROLLED_BACK,
    /**
     * The transaction has been marked for rollback only.
     */
over 4 years ago · Santiago Trujillo Relatório

0

Try

transaction.getStatus().canRollback()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda