根据另一个表中的数据从一个表中获取数据的正确 Hibernate 查询是什么?
我有两个表,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像左连接,即表的全部加上连接的表(如果引用)。
这是关于 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/