-->
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.  [ 6 posts ] 
Author Message
 Post subject: different databases simultaneously
PostPosted: Wed Jan 10, 2007 5:35 pm 
Newbie

Joined: Wed Jan 10, 2007 5:20 pm
Posts: 8
I'm using hibernate in my struts web application and I need to connect to different databases simultaneously.
Can Anyone tell me how to do that ?
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 8:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The question is not defined very well... anyway.

1) Use Java Threads - create two - then using the two SessionFactories (one for each database) each thread then accesses the databases 'simultaneously' assuming you have a multi-core/cpu platform (and the OS allocated the threads as such).

2) Assuming you meant in sequence usder the same Transaction - you need to setup the JDBC connections to use a TX data source and use an appripately setup Transaction manager (JTA is the usual approach).


Top
 Profile  
 
 Post subject: accessing different database
PostPosted: Thu Jan 11, 2007 10:56 am 
Newbie

Joined: Wed Jan 10, 2007 5:20 pm
Posts: 8
THX,
It's true the question wasn't defined very well.
Actually, In my application I have independent ajax components that do their own database access through Hibernate, but these queries must be done on different database.
That's why I said that I want to access to different databases simulatneously.
In consequence, I think the first solution you gave is more convenient in my situation.
For the moment I'm using the following code to create a SessionFactory.

[i]sessionFactory = new Configuration().configure().buildSessionFactory();[/i]

[b]I suppose I will have to create a second hibernate.cfg.xml to access to a second database.[/b] If not, please let me know...
[b]But then, how do I must write my code in order to access to the second hibernate.cfg.xml ?[/b]

thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 12:22 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you can specify the config file to load when you make the Configuration object

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 4:10 pm 
Newbie

Joined: Wed Jan 10, 2007 5:20 pm
Posts: 8
Can you give more details about how to do it please?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 4:25 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
Configuration conf1 = new Configuration();
conf1.configure(new File("/some/folder/hibernate1.cfg.xml"));
conf1.buildSessionFactory();

Configuration conf2 = new Configuration();
conf2.configure(new File("/some/other/folder/hibernate2.cfg.xml"));
conf2.buildSessionFactory();




http://www.hibernate.org/hib_docs/v3/api/

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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