-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Configuring Hibernate for multiple databases
PostPosted: Mon May 07, 2007 5:06 am 
Newbie

Joined: Mon May 07, 2007 5:00 am
Posts: 3
Hi all,

I have a requirement in which I should be able to connect to multiple databases dynamically using Hibernate.

I can use multiple configuration files and call configure(String filename) to create SessionFactory object. But my requirement is that multiple databases get connected dynamically which I am unaware of, so I would not be able to configure them in prior using separate config files.

I would like to explain the architecture we have-
There is a GUI, a controller and a model. This model could be a distributed one, ie., there can be no. of datasources running in multiple servers.

For the connectivity between the controller and the model, we are using Hibernate. And these datasources are connected dynamically to the controller at run-time. Hence we do not know the connectivity parameters beforehand. So, how to resolve this?

Thanks,
Deepa


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 6:30 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,

>>>i) I have a requirement in which I should be able to connect to multiple databases dynamically using Hibernate.
ii) I would not be able to configure them in prior using separate config files.


You can build the Configuration Object and SessionFactory at run-time when connection parameters are available.
It is not mandatory to have configuration files. ( hibernate.cfg.xml )

org.hibernate.Configuration configuration = new org.hibernate.Configuration() ;
configuration.addResource("MyMapping.hbm.xml") ;

String myDriverClass ; // I get the value at run time.
Properties p = new Properties() ;
p.setProperty("connection.driver_class", myDriverClass ) ;
...... // set required properties
configuration.setProperties(p) ;
configuration.buildSessionFactory() ;


However,
i) Creation of sessionFactory takes time ( normally done at setup).
ii) Handle it properly, once created. ( do not resort to re-creation )

------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.