Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...