File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes how to use 2 database in hibrnates. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "how to use 2 database in hibrnates." Watch "how to use 2 database in hibrnates." New topic
Author

how to use 2 database in hibrnates.

sure nandu
Greenhorn

Joined: Oct 16, 2006
Posts: 18
hai everybody,

i just wanted to know how can we use 2 databases using hibernates.
--> to create some tables in mysql server and some other databases
in say oracle server. we can define 2 sessionfactory in
<hibernate-configuration>. but how to specify specific table to be created
in particular database.
if anyone knows please reply.any response will be appreciated. thank you.

regards
nandu
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You want to create one logical model that spans two physical databases of different types? That is a very unusual setup. Typically, if you did want to do this the databases would be the same type and you would let the database itself manage the data model, and Hibernate would just use it as if it were one database. Why do you need to do this?
[ November 10, 2006: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sure nandu
Greenhorn

Joined: Oct 16, 2006
Posts: 18
thanks for the reply.
In one of the seminars i attended on hibernates i got this question.
so i just wanted to know whether it is possible to use 2 databases from hibernates in a single application.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ah perhaps I misunderstood your original question. Using two or more database from one application via Hibernate is easy. Just create a SessionFactory for each schema and swap as appropriate, Hibernate will manage the differences between the databases transparently.

Having one model split across two databases is not easy though.
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi to @ll, I'm not sure about how could I setup hibernate (either hibernate.cfg.xml or hibernate.properties) to use 2 databases?

Thanks in advance


"La verdadera sabidur�a viene del temor de Dios"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Just use two configurations. E.g. :
 
 
subject: how to use 2 database in hibrnates.
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com