I am using Hibernate 3.0 with JTA scoped session context (using getCurrentSession). I am storing a userId and transactionId in a as thread local variables. Using my own ConnectionProvider, I am pulling these variables from thread local and calling a stored procedure on the connection to set the database session identifier, before giving the connection to Hibernate.
My issue is that when hibernate flushes the changes to the database, it is using a seperate thread from the thread pool, and therefore it doesn't contain the same thread local variables as when the session was created.
I somehow need a way to access transactionId and user from any thread in the transaction, and also be able to use these values to call the stored procedure on the JDBC connection before handing it off to Hibernate.
|