title: Dynamically selecting data sources in Spring Hibernate - approaches
body: <p>Is there a simple way to Choose the datasource by reading from UI or a properties file using Spring and Hibernate, if for eg. the Datasources are X and Y. ?</p>
  
  <p>One approach would be to have dual configuration of sessionfactory, datasource and transaction manager. Then, based on the selection of datasource, the DAO is injected with the appropriate sessionfactory. Is there a better option?</p>
  
  <p>My scenario is that I should be able to switch between two databases on the fly as and when client requires a change in DB for the same application. </p>
  
  <p>Is it a good approach to have DAO with DB compatible methods for eg. a method to retrieve data from DB X and another method to retrieve Data from DB Y as data retrieval varies from one DB to another and calling the methods dynamically at run-time.</p>
  
  <p>or</p>
  
  <p>Is it a better approach to have different versions of same application altogether for X and Y databases for the sake of Database compatibility with java ? If this is the right approach I would like to understand why ?</p>