Switched from Hibernate 4.3.1 to 5.0.6 and Transaction is gone

前端 未结 1 870
轮回少年
轮回少年 2020-12-19 18:28

I am working on a Hibernate project.I had used Hibernate 4.3.1 libraries of Netbeans. Then I needed to use Apache Lucene for fulltext searching. To be able to use Lucene I n

相关标签:
1条回答
  • 2020-12-19 18:50

    wasRolledBack method is not included in the Hibernate 5.0.6 version Transaction interface Here .

    4.3.1 version that was taking place in the wasRolledBack method.

    Existing methods:

    public interface Transaction {
    
        void begin();
    
        void commit();
    
        void rollback();
    
        TransactionStatus getStatus();
    
        void registerSynchronization(Synchronization synchronization) throws HibernateException;
    
        void setTimeout(int seconds);
    
        int getTimeout();
    
        void markRollbackOnly();
    
     }
    

    I did not test, but you can use the getStatus method.

    Example:

        TransactionStatus transactionStatus = session.getTransaction().getStatus();
        if(transactionStatus.equals(TransactionStatus.ROLLED_BACK)){
            //action s.a :)
        }
    

    EDIT 1:

    TransactionStatus Enum Constant and Description:

    ACTIVE : The transaction has been begun, but not yet completed.

    COMMITTED : The transaction has been competed successfully.

    COMMITTING :Status code indicating a transaction that has begun the second phase of the two-phase commit protocol, but not yet completed this phase.

    FAILED_COMMIT:The transaction attempted to commit, but failed.

    MARKED_ROLLBACK:The transaction has been marked for rollback only.

    NOT_ACTIVE:The transaction has not yet been begun

    ROLLED_BACK:The transaction has been rolled back.

    ROLLING_BACK:Status code indicating a transaction that is in the process of rolling back.

    0 讨论(0)
提交回复
热议问题