Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

java - Switched from Hibernate 4.3.1 to 5.0.6 and Transaction is gone

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 needed to switch to Hibernate 5.x jars.I can define a new Transaction object but wasRollecBack method of Transaction class is not working. I used this method in several places and now I'm stuck. When I look at javadoc of Hibernate 5.0.6 there is nothing like org.hibernate.transaction . There is org.hibernate.engine.transaction but it does not work either.

When I get back to 4.3.1 wasRolledBack is working but this time I cant run project with lucene libraries. I am confused.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...