Pass DB connection on the fly to hibernate session for the DAO based on spring-HibernateDaoSupport
posted 5 years ago
I am developing an application based on spring hibernate using myeclipse .
I generated Spring DAOs using database explorer and manage to do different DB operations for testing, using a static datasource defined in the applicationContext.xml (NOT THE ONE BELOW)
Now, for the actual application. Each user in my company has his own Oracle user. Therefore it is required to use individual user based connection for any application.
So for each hibernate session I have to create a new oracle connection based on the individual user. Datasources and ConnectionPool does not work here.
(Grrrrr I know, you will not find this in normal applications but this is how our environment works.)
I have generated DAO based on myeclipse and each DAO is extended by default by org.springframework.orm.hibernate3.support.HibernateDaoSupport class which uses getHibernateTemplate() method to execute database operations. Internally HibernateDaoSupport class uses the default session factory as shown in the below applicationContext.xml where I don’t specify the Oracle connection details as I want to pass the connection on the fly.
Is there a way to pass the oracle connection to hibernate session for the generated DAOs?