• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use 2 database in hibrnates.

 
sure nandu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sure nandu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use two configurations. E.g. :
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic