Forums Register Login

Accessing two databases through hibernate.

+Pie Number of slices to send: Send
Hi Friends,

I want to access two SQL SERVER 2000 databases in my application through Hibernate. Can anyone help me how to write the configuration file(cfg.xml) for this? Help needed urgent please............ Thanks in Advance.
+Pie Number of slices to send: Send
You will need to create a session factory for each database, so you will need two cfg.xml files. No other way around this, I'm afraid.
+Pie Number of slices to send: Send
Hi Paul,

Thanks for the reply. I'm new to hibernate. How to load two cfg files in a single instance.
+Pie Number of slices to send: Send
What do you mean by "single instance"? You cannot have a SessionFactory configured to use more than one DataSource, so you need two SessionFactory instances.
+Pie Number of slices to send: Send
Your application will end up having to SessionFactory objects, one for each database your are connecting to. When you create a SessionFactory, it will look for hibernate.cfg.xml by default, but you can tell it to look for a specific config file, such as hibernate_01.cfg.xml and hibernate_02.cfg.xml.

Be careful, though. You're object model will not be able to use Hibernate to map associated classes across databases. To do that, you would need to use something like Hibernate Shards, which hasn't quite gone ga yet.

-Cameron McKenzie
+Pie Number of slices to send: Send
Hi Paul and Cameron,

I really appreciate your help. Let me try these stuffs.
Those are the largest trousers in the world! Especially when next to this ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2664 times.
Similar Threads
Problem managing session with multiple data sources
Two SessionFactory Objects
How do you implement a clustered database?
Connecting two different databases using Hibernate
what’s the best practice to config Hibernate-Spring for multiple database relationship?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:37:38.