• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple DataBase access in Hibernate.

 
rex antony
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In Hibernate,how we've to connect more than one database (like mysql,oracle).I've already searched into Net.I dont get any example code or idea for that.
Thanks in advance.
Thanks and Regards
Rex
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have a SessionFactory for each database, and create a Session from each one, you cannot have one Session or one SessionFactory point to multiple databases. Just like you cannot have a single JDBC Connection point to multiple databases. Basically a SessionFactory uses one Connection Pool, that holds One Connection in One Session, that type of Connection is a JDBC Connection. So since you can't do it in JDBC Connections, you can't do it with a Hibernate Session or SessionFactory.

I just added the last part to point out that it is not Hibernate's issue/fault, but underlying JDBC.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic