问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/57279329/migrating-hibernate-3-6-to-5-1-generates-exception-in-hibernateutils