Hibernate version: 3.3.0 CR1
Name and version of the database you are using: MS SQL Server 2005
I have a web application that consists of various servlets and JSP pages, with Hibernate at the back-end. I am using the "Open Session In View" model, implemented as a servlet filter that opens the transaction and commits/rolls back at the end.
This works great for the servlets and most of the JSP pages. However, I now have a JSP page that needs to open and commit/rollback a separate transaction on the same database without affecting the session opened by the servlet filter (the reason I need to do this relates to software design that I can not change, the details are too gory to get into here). This separate transaction only reads data, it does not write data, if that simplifies things.
I remember reading something about suspending transactions a while ago when I didn't need to do it, and now I can't remember what I read or where I read it. I seem to remember something about being able to suspend the current transaction, start and complete a new one, then resume the old? What's a good way to make this work? Currently, the servlet filter does something like this around the whole request (I've simplified a lot of the code here, left out logging, exception handling on rollback, and I also have the ability to roll back even if an exception is not thrown):
Code:
Session s = mySessionFactory.getCurrentSession();
try {
s.beginTransaction();
handleRequest(...);
s.commitTransaction();
} catch (Throwable t) {
s.rollbackTransaction();
}
And the "inner" transaction is opened / closed in a similar way. So, the question is: What's the best way to put that "inner" transaction inside the servlet filter transaction and still have everything work OK?
Thanks,
JC