0

我有两个不同的数据库(在同一台服务器上),我想跨数据库连接表。我正在使用 Hibernate,是否可以在 hibernate 中创建一个可以连接这些数据库中的两个表的查询?

4

1 回答 1

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.

于 2013-05-16T09:53:20.310 回答