是否可以在hibernate中应用一个使用两个数据库的查询? [英] is it possible to apply a query in hibernate which uses two databases?

查看:90
本文介绍了是否可以在hibernate中应用一个使用两个数据库的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

Hibernate将为您的HQL或Criteria查询创建一个SQL查询,并且此SQL将通过jdbc发送到数据库。这意味着hibernate不支持你想要做的事情。



但是,在某些情况下,你可以得到相同的结果。某些数据库提供了为位于不同数据库中的表创建别名的选项。因此,您将能够编写一个SQL查询,它连接两个表并在数据库上执行它。



我们正在使用DB2。
如果你可以这样做,这取决于你的数据库。



我猜想,如果你有两个不同的数据库(例如DB2和MySQL),但是如果两个数据库都是同一个供应商,那么这是不可能的。 / p>

您应该尝试在数据库服务器的文档中找到更多信息。


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?

解决方案

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.

这篇关于是否可以在hibernate中应用一个使用两个数据库的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆