-->
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.  [ 3 posts ] 
Author Message
 Post subject: Connecting to 2 DB in one session at a time ...
PostPosted: Fri Jul 28, 2006 1:01 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
I have a requirement of connecting to 2 DB in one session at a time ...

Detailed explan : In my application when my application starts hibernate is configured to interact with a DB which is meant for my application.I am using Data source for obtaining a connection from this database.
Now in one of my module, I have to connect to another 3rd party DB and execute few stored procedure on it.
Now question is , how do I connect to these two DB in one session at a time

Can I specify 2 data source in my one hibernate.cfg.xml and while initialising session factory I can specify the specific data source....

Any clue please

thanks and regards,

sudhir


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:30 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
I don't beleive it's possible to have a Session having to connect to multiple DBs. Read Section 3.2 of the documentation. Since Session is created out of SessionFactory and SessionFactory is usually bound to 1 DB or 1 Data source.

I beleive the reason is that this restriction facilitates the 1st level caching of data at the Session level as if it were to connect to 2 DBs it would result in unknown behaviour.

You will have to use 2 different session factories and obtain the relevant factory and session from that. You could create multiple confiigurations and bind the 2 Factories to a JNDI and lookup the corresponding factory in your application as applicable.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:45 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Thanks Anand, I am aware @ option of having multiple configuration files for individual DB......but still wanted to take a chance, where in , there might be some other soln......

thanks any ways

sudhir


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.