Is there a way to create different db connection in runtime using hibernate.
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.
If you want to manage transaction for all databases, can you do that with Hibernate?
For instance, I want to update data on both databases, but the first transaction on a DB has to be rollback after second transaction on the other DB fails. How can you handle this kind scenario?
I've posted this topic Transaction management on multiple DB connections as new.