The short question: is there a way to determine if a particular session object is already associated with a transaction (i.e. has already called beginTransaction())?
And if you want to know why I need to know ....
I have sort coded myself into a corner by putting a call to getSession() in some old legacy code. Mainly as a convenience to obtain a connection. This of course creates a connection leak since I do not explicitly close it.
Well, now I have to fix it. Problem is this code is called by code within a Hibernate transaction while other older code also calls it that is not within a transaction. So if I explicitly close the session to handle the leak, I will break the code that is running in a transaction since I will invalidate the session by calling close().
|