OK, what I take from the referenced documentation is, assuming I do not use auto-commit, I should always use beginTransaction() and commit().
To be honest I still don't quite understand why this will take care of my issue. When I look at the API documentation for the Transaction.commit() I see that commit "flushs the associated Session and ends the unit of work." Is the key here "ends the unit of work"?
My situation is a little more complicated than I original stated. The code sample I provided is actually a small part of a larger Transaction. A higher level view of my code is:
Code:
try {
Session hSession = HibernateUtil.getSession();
hSession.beginTransaction();
<do a bunch of things ....>
<perform code sample below >
< do a buch more things ... >
hSession.getTransaction().commit();
}
catch (Exception e) {
hSession.getTransaction().rollback();
}
The point I want to make is that if I run into a probem and need to rollback I need to rollback a lot more than the code sample provided below. Can I do multiple commits for each beginTransaction()? If so, and I have to do a rollback, will I rollback to the beginTransaction() or to the last commit()?
I appreciate your help. :)