Hibernate version:
2.1.7 (previous versions too)
Mapping documents:
not needed
Code between sessionFactory.openSession() and session.close():
see util classes
Full stack trace of any exception that occurs:
Name and version of the database you are using:
tested with Oracle 8i
The generated SQL (show_sql=true):
none
Debug level Hibernate log excerpt:
http://www.hibernate.org/hib_docs/api/n ... Committed()
Hi firends,
to have a transparent and pseudo _automatic_ (don't like this) transaction holding, most of us are working with util classes like the one written by Christian in caveatemptor
Code:
public static void commitTransaction()
throws InfrastructureException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if ( tx != null && !tx.wasCommitted()
&& !tx.wasRolledBack() ) {
log.debug("Committing database transaction of this thread.");
tx.commit();
}
threadTransaction.set(null);
} catch (HibernateException ex) {
rollbackTransaction();
throw new InfrastructureException(ex);
}
}
/**
* Rollback the database transaction.
*/
public static void rollbackTransaction()
throws InfrastructureException {
Transaction tx = (Transaction) threadTransaction.get();
try {
threadTransaction.set(null);
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
log.debug("Tyring to rollback database transaction of this thread.");
tx.rollback();
}
} catch (HibernateException ex) {
throw new InfrastructureException(ex);
} finally {
closeSession();
}
}
i have exactly the same tests in mine to know if a transaction has been committed.
But the Javadoc says :
Quote:
Check if this transaction was successfully committed. This method could return false even after successful invocation of commit().
I've checked with Oracle and it's totally true (so well documented ;)), sometimes after a successfull commit, this method returns true, but sometimes not.
Is it related to jdbc? does JTA offer the same behaviour?
Next question: seeing this, our code might be broken so is there a workaround?
should we manage a boolean inside the util class ?
Have a nice week end