0

I have two different databases (on same server) and i want to join tables across databases. I am using Hibernate, is it possible to create a query in hibernate which can join two tables in those databases?

Toseef Zafar
  • 1,601
  • 4
  • 28
  • 46

1 Answers1

2

Hibernate will create an SQL query for your HQL or Criteria query and this SQL will be sent through jdbc to the database. This means that hibernate does not support for what you are trying to do.

However, you can achieve the same result in some cases. Some databases give you the option to create an alias for a table that resides in a different database. So you will be able to write an SQL query that joins the two tables and execute it on the database.

We are doing that with DB2. If you can do that, it depends on your database.

I guess, that it would impossible if you have two different databases (example DB2 and MySQL) but if both databases are of the same vendor, then maybe it's achievable.

You should try to find more info in you database server's documentation.

nakosspy
  • 3,904
  • 1
  • 26
  • 31
  • Thanks for your comment. I am using mySQL and both databases are on same server. I will try to find if MySQL supports the alias thing. – Toseef Zafar May 16 '13 at 09:56