jzhuo wrote:
I have a project now to use hibernate, the scene is following:
(1) I have a thread pool to manage threads for business handling.
(2) In every thread, it maybe access several datasources(two or three database servers)
(3) To every datasource, thread maybe access to the several tables.
I study the ThreadLocal sample (in document 42.html) and several other examples, but I have some questions:
(1) when should i invoke the method closeSession? (in these examples, I can find nowhere to invoke this method.)
At the end of each Unit of Work. Which is most cases is the end of the transaction.
Quote:
(2) Do you have some better ways to be fit for my situation?Thanks.
No - sounds like SLSB but your doing the work for yourself. Just don't
use the same session in different threads. You avoid this with ThreadLocal.
Quote:
(3) In a thread, how can i manage several datasource?
You need to create multiple SessionFactories, eg, One for each different datasource.