Hibernate version:2.1.6
Hi Guys:
For my Stand alone application , I m trying to use Hibernate for persistence layer. Currently, the stand alone application is using direct JDBC for Data access. We are trying to change it to Hibernate. We are connecting to 4 different databases with different data modelling. I know that I need to configure multiple SessionFactory objects.
Is there a clean way of doing it.
Code:
public class FactoryDude {
public static SessionFactory createDB1SessionFactory(){
...
}
public static SessionFactory createDB2SessionFactory(){
...
}
}
In my DAO layer , instead of using SessionFactory could I use SessionManager interface .
Code:
public interface SessionManager {
public Session getSession();
public void removeSession();
}
The SessionManager implementation class will hold the Session in ThreadLocal.
This is where I am kind of stuck.
Lets Consider ,
UserDAO (needs to get data from DB1) and ItemDAO ( needs to get data from DB2). Both of them will having their own instance of SessionManager.
In this scenerio , how does ThreadLocal works. Will I be always getting DB1Session when called from UserDAO and DB2Session when called from ItemDAO?
I am sorry for this long message, I was trying to be as clear as possible.
Thank you,