• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic schema switch in Hibernate

 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,

I have a requirement of dynamic switching of database .i.e, we have a screen which requires inputs such as databse url , username/pswd in some way . User can select the DB and connection will happen depending on inputs . This is implemented in JDBC. Now i am switching it to Hibernate . Please let me know how i could change the DB dynamically in hibernate. is their a way to modify hibernate.cfg.xml dynamically ? or how ?


Thanks in advance ..
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure about the details or if it would actually work, but maybe you can create different Data Sources for your DBs and then set the Data Source dynamically to your hibernate SessionFactory?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way is to configure two SessionFactories. SessionFactories are heavy weight components; you don't want to be reconfiguring them based on user input. There is a one to one mapping between a SessionFactory and its DataSource, your DAO layer can switch based on the parameters you pass.
 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henrique Ordine wrote:I'm not really sure about the details or if it would actually work, but maybe you can create different Data Sources for your DBs and then set the Data Source dynamically to your hibernate SessionFactory?


Thanks for your suggestion Henrique ...
 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:The easiest way is to configure two SessionFactories. SessionFactories are heavy weight components; you don't want to be reconfiguring them based on user input. There is a one to one mapping between a SessionFactory and its DataSource, your DAO layer can switch based on the parameters you pass.


Thank you for your suggestion Paul Sturrock. Hope it could work .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic