My web application needs to support two databases either MS-SQL or Oracle. My application will be deployed on Weblogic Server. Users will be creating a datasource (either MS-SQL or Oracle) in Weblogic Server.
As my application need to support many databases i have decided to use hibernate, so that i can code to HQL rather than SQL.
Can i configure Hibernate Service based on the datasource created in Weblogic so that i can configure the hibernate dialect and other stuff dynamically.
My requirement is that not to support multiple databases at a time, but rather my application should configure (connect) a single database dynamically using hibernate.
one you can always instantiate your SessionFactory in code, so in code you could say read a .properties file that has the datasource information. Then load that info when creating the SessionFactory.
You could just have the datasource name that is put into jndi in the App Server always be the same name, so all you need in your Hibernate config file is pointing to the jndi name, then just swap out the datasource definition in the App Server.
You could use Spring to have different xml config files that define the Datasource bean and the Factory and inject them into your DAO classes.
Well the thing is, a SessionFactory is one to one with a database datasource/connection so just one dialect. So you would declare different SessionFactories for each datasource. You really can't dynamically switch out a dialect in the middle of your app. You can when you create your Configuration object, which you pass to the SessionFactory, but once the SessionFactory is created, that instance is immutable. It cannot be changed.