Class HibernateTransactionManager

All Implemented Interfaces:
SynchronousTransactionManager<org.hibernate.Session>, TransactionManager, TransactionOperations<org.hibernate.Session>

@EachBean(javax.sql.DataSource.class) @Replaces(DataSourceTransactionManager.class) @Requires(condition=io.micronaut.transaction.hibernate.HibernateTransactionManagerCondition.class) public final class HibernateTransactionManager extends AbstractDefaultTransactionOperations<org.hibernate.Session>
The Hibernate transaction manager. Partially based on https://github.com/spring-projects/spring-framework/blob/main/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java
Since:
4.0.0
Author:
Denis Stepanov
  • Method Details

    • doBegin

      protected void doBegin(DefaultTransactionStatus<org.hibernate.Session> txStatus)
      Description copied from class: AbstractTransactionOperations
      Begin a new transaction with semantics according to the given transaction definition. Does not have to care about applying the propagation behavior, as this has already been handled by this abstract manager.

      This method gets called when the transaction manager has decided to actually start a new transaction. Either there wasn't any transaction before, or the previous transaction has been suspended.

      Specified by:
      doBegin in class AbstractTransactionOperations<DefaultTransactionStatus<org.hibernate.Session>,org.hibernate.Session>
      Parameters:
      txStatus - The transaction
    • doCommit

      protected void doCommit(DefaultTransactionStatus<org.hibernate.Session> tx)
      Description copied from class: AbstractTransactionOperations
      Perform an actual commit of the given transaction.

      An implementation does not need to check the "new transaction" flag or the rollback-only flag; this will already have been handled before. Usually, a straight commit will be performed on the transaction object contained in the passed-in status.

      Specified by:
      doCommit in class AbstractTransactionOperations<DefaultTransactionStatus<org.hibernate.Session>,org.hibernate.Session>
      Parameters:
      tx - The transaction
    • doRollback

      protected void doRollback(DefaultTransactionStatus<org.hibernate.Session> tx)
      Description copied from class: AbstractTransactionOperations
      Perform an actual rollback of the given transaction.

      An implementation does not need to check the "new transaction" flag; this will already have been handled before. Usually, a straight rollback will be performed on the transaction object contained in the passed-in status.

      Specified by:
      doRollback in class AbstractTransactionOperations<DefaultTransactionStatus<org.hibernate.Session>,org.hibernate.Session>
      Parameters:
      tx - The transaction
    • getConnection

      @NonNull public @NonNull org.hibernate.Session getConnection()
      Description copied from interface: TransactionOperations
      Obtains the connection for the current transaction.
      Returns:
      The connection
    • hasConnection

      @NonNull public @io.micronaut.core.annotation.NonNull boolean hasConnection()
      Description copied from interface: TransactionOperations
      Check if the connection exists.
      Specified by:
      hasConnection in interface TransactionOperations<org.hibernate.Session>
      Overrides:
      hasConnection in class AbstractTransactionOperations<DefaultTransactionStatus<org.hibernate.Session>,org.hibernate.Session>
      Returns:
      True if transaction exists