I was trying to use the thread local pattern for my hibernate application, and I am unconfortable with the following facts. (note: I am using j2ee transaction semantics-CMT)
Case1: If the tread local is handled at the servlet(presentation tier). That means the sevlet is responsible for calling the closeSession.
* If the application is deployed in a cluster,one of your ejb can call another ejb which resides in the second node. The transaction flow in this case would be for instance Container1Servlet1---->Container1EJB1---->Container2EJB2. Since Thread Local won't be propagated across containers, the Container2EJB2 will create a new session and use that. And now Container1Servlet1 is not aware of that session and it closes only the first session created by him.
Case2: If the thread local is handled by each of the EJBs. That means that each EJB method is responsible for calling the closeSession at the end of the execution.
* If the transaction flows is like Container1Servlet1---->Container1EJB1(M1-TXRequiresNew) ---->Container1EJB1(M2-TXRequired) In this scenario, I cannot implement the session-per-request or not even session-per-transaction and results in poor performance. Because M1 and M2 has to open and close the session by its own.
Any input would be appreciated.
|