根据另一个表中的数据从一个表中获取数据的正确 Hibernate 查询是什么?

发布于 2025-01-04 20:08:29 字数 534 浏览 1 评论 0原文

我有两个表,Device 包含设备的详细信息,包括是否已分配设备,而 CustDevice 包含已分配给客户的设备的附加信息。

如果设备表已分配给特定客户,我需要从设备表中选择记录。

我对查询的第一个天真的尝试是:

from Device where Device.deviceId = CustDevice.deviceId and Device.status=2 and CustDevice.accountId=33

这显然不起作用,但它解释了我的关系我正在努力做。 我尝试在混合中添加联接,但我不知道联接两个表的正确语法。

我尝试过:

from Device dev join dev.deviceId CustDevice where dev.deviceId = CustDevice.deviceId and dev.deviceStatus = 2 and CustDevice.accountId=33

但这也不起作用。 谁能帮我解决这个问题吗? 谢谢

I have two tables, Device contains details of a device, including if it is assigned, and CustDevice which contains additional information for devices that have been assigned to a customer.

I need to select records from the Device table if it has been assigned to a particular customer.

My first naive stab at a query was:

from Device where Device.deviceId = CustDevice.deviceId and Device.status=2 and CustDevice.accountId=33

That obviously does not work, but it explains the relationship I am trying to do.
I attempted to add a join in the mix, but I do not know the proper syntax for joining two tables.

I tried:

from Device dev join dev.deviceId CustDevice where dev.deviceId = CustDevice.deviceId and dev.deviceStatus = 2 and CustDevice.accountId=33

But that doesn't work either.
Can anyone help me out with this query??
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱你是孤单的心事 2025-01-11 20:08:29

这听起来像左连接,即表的全部加上连接的表(如果引用)。

这是关于 Hibernate 中左连接的文章。

http:// www.jairrillo.com/blog/2009/01/29/how-to-use-left-join-in-hibernate-criteria/

This sounds like a left join, that is all of a table plus the joined table if it is referenced.

Here is and article on left joins in Hibernate.

http://www.jairrillo.com/blog/2009/01/29/how-to-use-left-join-in-hibernate-criteria/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文