It looks like my problem lies with closing the session before the transaction has time to finish. My code followed this
pattern:
Session session = factory.openSession();
try {
// Do hibernate work here...
session.flush();
} catch( HibernateException exception ) {
// Log exception.
} finally {
session.close();
}
I changed it to do the following:
Session session = factory.openSession();
Transaction transaction = session.beginTransaction();
try {
// Do hibernate work here...
transaction.commit();
} catch( HibernateException exception ) {
transaction.rollback();
// Log exception.
} finally {
session.close();
}
The addition of the Transaction API has made the code run much more consistently. It seems that the faster the computer is, the more likely the non-transaction pattern seems to fail. It looks like flush() just doesn't get the work done before the session is closed. I'm not sure if I am using Hibernate incorrectly just yet or if there is a bug in the flush() method in Hibernate's Session class.