This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi, Is there a way to create different db connection in runtime using hibernate. i.e i have 3 databases and i need three connections based on a particular condition...if there is a way please let me know
You need to create three distinct SessionFactories if you have three distinct DataSources. Any conditional code to select which source you use would normally be in your DAO factory class (assuming you are using thge DAO parrten)
Hi, Thanks for your reply.We have three different databases.So which is the easiest way to get the data source ,by having 3 different hibernate.cfg.xml or by getting 3 different data sources form app server using jndi.
Its a one to one mapping between a DataSource and a SessionFactory, so you will need three seperate configurations for your SessionFactory. So if you use hibernate.cfg.xml to do this you will need three versions, one for each DataSource.
or by getting 3 different data sources form app server using jndi.
Not sure I follow this part of your question. You can avoid this. If you have three different databases you will need three different DataSources in JNDI.
Joined: Jul 12, 2007
Hi, Thanks for your suggestion.I will create 3 hibernate.cfg.xml as you said